8000 Weird behaviour of suptitle() when horizontalalignment is not 'center' · Issue #12197 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Weird behaviour of suptitle() when horizontalalignment is not 'center' #12197
Closed
@gansanay

Description

@gansanay

Bug report

Bug summary

horizontalalignment = 'left' aligns the title on the right, horizontalalignment = 'right' aligns a short title on the left, horizontalalignment = 'right' displaces a longer title on the far left

Code for reproduction

# Left alignment test, short title
fig = plt.figure(figsize=(9,4))
ax = fig.add_subplot(111)
fig.suptitle('This figure suptitle should be on the left', horizontalalignment = 'left')
ax.set_title('This axis title should be on the left', loc='left');
fig.savefig('left_align.png')

# Right alignment test, short title
fig = plt.figure(figsize=(9,4))
ax = fig.add_subplot(111)
fig.suptitle('This figure suptitle should be on the right', horizontalalignment = 'right')
ax.set_title('This axis title should be on the right', loc='right');
fig.savefig('right_align.png')

# Right alignment test, longer title
fig = plt.figure(figsize=(9,4))
ax = fig.add_subplot(111)
fig.suptitle('This figure suptitle should be on the right but it is far left', horizontalalignment = 'right')
ax.set_title('This axis title should be on the left', loc='left')
fig.savefig('far_left.png');

Actual outcome

  • Left alignment test, short title
    left_align

  • Right alignment test, short title
    right_align

  • Right alignment test, longer title
    far_left

Expected outcome

The following code manually sets the figure title at the expected position:

fig = plt.figure(figsize=(9,4))
ax = fig.add_subplot(111)
fig.suptitle('This figure suptitle is long but it is manually positioned', x = 0.38)
ax.set_title('This axis title should be on the left', loc='left')
fig.savefig('manual_pos.png');

Which gives:
manual_pos

Matplotlib version

  • Operating system: Windows
  • Matplotlib version: 2.1.2 and 2.2.3
  • Matplotlib backend: agg
  • Python version: 3.6.4
  • Jupyter version: 4.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationGood first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0