Skip to content

Backport PR #13741 on branch v3.1.x (FIX: make title move above ticklabels) #13755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2536,8 +2536,9 @@ def _update_title_position(self, renderer):
top = 0
for ax in axs:
try:
if (ax.xaxis.get_label_position() == 'top'
or ax.xaxis.get_ticks_position() == 'top'):
choices = ['top', 'unknown']
if (ax.xaxis.get_label_position() == 'top' or
ax.xaxis.get_ticks_position() in choices):
bb = ax.xaxis.get_tightbbox(renderer)
else:
bb = ax.get_window_extent(renderer)
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5724,6 +5724,16 @@ def test_title_xticks_top():
assert ax.title.get_position()[1] > 1.04


def test_title_xticks_top_both():
# Test that title moves if xticks on top of axes.
fig, ax = plt.subplots()
ax.tick_params(axis="x", bottom=True, top=True,
labelbottom=True, labeltop=True)
ax.set_title('xlabel top')
fig.canvas.draw()
assert ax.title.get_position()[1] > 1.04


def test_offset_label_color():
# Tests issue 6440
fig = plt.figure()
Expand Down