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

Skip to content

Commit 20387f7

Browse files
authored
Merge pull request #13741 from jklymak/fix-move-title-ticklabels
FIX: make title move above ticklabels
2 parents e974bf0 + b4a1a97 commit 20387f7

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,8 +2535,9 @@ def _update_title_position(self, renderer):
25352535
top = 0
25362536
for ax in axs:
25372537
try:
2538-
if (ax.xaxis.get_label_position() == 'top'
2539-
or ax.xaxis.get_ticks_position() == 'top'):
2538+
choices = ['top', 'unknown']
2539+
if (ax.xaxis.get_label_position() == 'top' or
2540+
ax.xaxis.get_ticks_position() in choices):
25402541
bb = ax.xaxis.get_tightbbox(renderer)
25412542
else:
25422543
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
@@ -5723,6 +5723,16 @@ def test_title_xticks_top():
57235723
assert ax.title.get_position()[1] > 1.04
57245724

57255725

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

0 commit comments

Comments
 (0)