File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -2614,7 +2614,6 @@ def _update_title_position(self, renderer):
2614
2614
Update the title position based on the bounding box enclosing
2615
2615
all the ticklabels and x-axis spine and xlabel...
2616
2616
"""
2617
-
2618
2617
if self ._autotitlepos is not None and not self ._autotitlepos :
2619
2618
_log .debug ('title position was updated manually, not adjusting' )
2620
2619
return
@@ -2637,7 +2636,7 @@ def _update_title_position(self, renderer):
2637
2636
else :
2638
2637
ax .apply_aspect ()
2639
2638
axs = axs + [ax ]
2640
- top = 0
2639
+ top = - np . Inf
2641
2640
for ax in axs :
2642
2641
if (ax .xaxis .get_ticks_position () in ['top' , 'unknown' ]
2643
2642
or ax .xaxis .get_label_position () == 'top' ):
@@ -2646,6 +2645,11 @@ def _update_title_position(self, renderer):
2646
2645
bb = ax .get_window_extent (renderer )
2647
2646
if bb is not None :
2648
2647
top = max (top , bb .ymax )
2648
+ if top < 0 :
2649
+ # the top of axes is not even on the figure, so don't try and
2650
+ # automatically place it.
2651
+ _log .debug ('top of axes not in the figure, so title not moved' )
2652
+ return
2649
2653
if title .get_window_extent (renderer ).ymin < top :
2650
2654
_ , y = self .transAxes .inverted ().transform ((0 , top ))
2651
2655
title .set_position ((x , y ))
Original file line number Diff line number Diff line change @@ -5430,6 +5430,19 @@ def test_title_xticks_top_both():
5430
5430
assert ax .title .get_position ()[1 ] > 1.04
5431
5431
5432
5432
5433
+ def test_title_no_move_off_page ():
5434
+ # If an axes is off the figure (ie. if it is cropped during a save)
5435
+ # make sure that the automatic title repositioning does not get done.
5436
+ mpl .rcParams ['axes.titley' ] = None
5437
+ fig = plt .figure ()
5438
+ ax = fig .add_axes ([0.1 , - 0.5 , 0.8 , 0.2 ])
5439
+ ax .tick_params (axis = "x" ,
5440
+ bottom = True , top = True , labelbottom = True , labeltop = True )
5441
+ tt = ax .set_title ('Boo' )
5442
+ fig .canvas .draw ()
5443
+ assert tt .get_position ()[1 ] == 1.0
5444
+
5445
+
5433
5446
def test_offset_label_color ():
5434
5447
# Tests issue 6440
5435
5448
fig = plt .figure ()
You can’t perform that action at this time.
0 commit comments