Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a65a91e

Browse files
authored
Merge pull request #13755 from meeseeksmachine/auto-backport-of-pr-13741-on-v3.1.x
Backport PR #13741 on branch v3.1.x (FIX: make title move above ticklabels)
2 parents 382a5b9 + 62a839b commit a65a91e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,8 +2536,9 @@ def _update_title_position(self, renderer):
25362536
top = 0
25372537
for ax in axs:
25382538
try:
2539-
if (ax.xaxis.get_label_position() == 'top'
2540-
or ax.xaxis.get_ticks_position() == 'top'):
2539+
choices = ['top', 'unknown']
2540+
if (ax.xaxis.get_label_position() == 'top' or
2541+
ax.xaxis.get_ticks_position() in choices):
25412542
bb = ax.xaxis.get_tightbbox(renderer)
25422543
else:
25432544
bb = ax.get_window_extent(renderer)

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5724,6 +5724,16 @@ def test_title_xticks_top():
57245724
assert ax.title.get_position()[1] > 1.04
57255725

57265726

5727+
def test_title_xticks_top_both():
5728+
# Test that title moves if xticks on top of axes.
5729+
fig, ax = plt.subplots()
5730+
ax.tick_params(axis="x", bottom=True, top=True,
5731+
labelbottom=True, labeltop=True)
5732+
ax.set_title('xlabel top')
5733+
fig.canvas.draw()
5734+
assert ax.title.get_position()[1] > 1.04
5735+
5736+
57275737
def test_offset_label_color():
57285738
# Tests issue 6440
57295739
fig = plt.figure()

0 commit comments

Comments
 (0)