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

Skip to content

Commit 6b84f24

Browse files
authored
Merge pull request #21398 from jklymak/fix-title-move-logic
FIX: logic of title repositioning
2 parents 94ac7a7 + b0d9f30 commit 6b84f24

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,13 +2979,13 @@ def _update_title_position(self, renderer):
29792979
axs = axs + [ax]
29802980
top = -np.Inf
29812981
for ax in axs:
2982+
bb = None
29822983
if (ax.xaxis.get_ticks_position() in ['top', 'unknown']
29832984
or ax.xaxis.get_label_position() == 'top'):
29842985
bb = ax.xaxis.get_tightbbox(renderer)
2985-
else:
2986+
if bb is None:
29862987
bb = ax.get_window_extent(renderer)
2987-
if bb is not None:
2988-
top = max(top, bb.ymax)
2988+
top = max(top, bb.ymax)
29892989
if top < 0:
29902990
# the top of Axes is not even on the figure, so don't try and
29912991
# automatically place it.

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5643,6 +5643,17 @@ def test_title_location_roundtrip():
56435643
ax.set_title('fail', loc='foo')
56445644

56455645

5646+
@pytest.mark.parametrize('sharex', [True, False])
5647+
def test_title_location_shared(sharex):
5648+
fig, axs = plt.subplots(2, 1, sharex=sharex)
5649+
axs[0].set_title('A', pad=-40)
5650+
axs[1].set_title('B', pad=-40)
5651+
fig.draw_without_rendering()
5652+
x, y1 = axs[0].title.get_position()
5653+
x, y2 = axs[1].title.get_position()
5654+
assert y1 == y2 == 1.0
5655+
5656+
56465657
@image_comparison(["loglog.png"], remove_text=True, tol=0.02)
56475658
def test_loglog():
56485659
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)