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

Skip to content

Commit de2336b

Browse files
committed
TST: Add a test for off page
1 parent f0e7c70 commit de2336b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ def _update_title_position(self, renderer):
26632663
bb = ax.get_window_extent(renderer)
26642664
if bb is not None:
26652665
top = max(top, bb.ymax)
2666-
if top < 0 or top > 1:
2666+
if top < 0:
26672667
# the top of axes is not even on the figure, so don't try and
26682668
# automatically place it.
26692669
_log.debug('top of axes not in the figure, so title not moved')

lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5533,6 +5533,19 @@ def test_title_xticks_top_both():
55335533
assert ax.title.get_position()[1] > 1.04
55345534

55355535

5536+
def test_title_no_move_off_page():
5537+
# If an axes is off the figure (ie. if it is cropped during a save)
5538+
# make sure that the automatic title repositioning does not get done.
5539+
mpl.rcParams['axes.titley'] = None
5540+
fig = plt.figure()
5541+
ax = fig.add_axes([0.1, -0.5, 0.8, 0.2])
5542+
ax.tick_params(axis="x",
5543+
bottom=True, top=True, labelbottom=True, labeltop=True)
5544+
tt = ax.set_title('Boo')
5545+
fig.canvas.draw()
5546+
assert tt.get_position()[1] == 1.0
5547+
5548+
55365549
def test_offset_label_color():
55375550
# Tests issue 6440
55385551
fig = plt.figure()

0 commit comments

Comments
 (0)