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

Skip to content

Commit f0e7c70

Browse files
committed
FIX: check if axes is off page before repositioning title
1 parent 71de09a commit f0e7c70

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,6 @@ def _update_title_position(self, renderer):
26322632
Update the title position based on the bounding box enclosing
26332633
all the ticklabels and x-axis spine and xlabel...
26342634
"""
2635-
26362635
if self._autotitlepos is not None and not self._autotitlepos:
26372636
_log.debug('title position was updated manually, not adjusting')
26382637
return
@@ -2655,7 +2654,7 @@ def _update_title_position(self, renderer):
26552654
else:
26562655
ax.apply_aspect()
26572656
axs = axs + [ax]
2658-
top = 0
2657+
top = -np.Inf
26592658
for ax in axs:
26602659
if (ax.xaxis.get_ticks_position() in ['top', 'unknown']
26612660
or ax.xaxis.get_label_position() == 'top'):
@@ -2664,6 +2663,11 @@ def _update_title_position(self, renderer):
26642663
bb = ax.get_window_extent(renderer)
26652664
if bb is not None:
26662665
top = max(top, bb.ymax)
2666+
if top < 0 or top > 1:
2667+
# the top of axes is not even on the figure, so don't try and
2668+
# automatically place it.
2669+
_log.debug('top of axes not in the figure, so title not moved')
2670+
return
26672671
if title.get_window_extent(renderer).ymin < top:
26682672
_, y = self.transAxes.inverted().transform((0, top))
26692673
title.set_position((x, y))

0 commit comments

Comments
 (0)