File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Original file line number Diff line number Diff line change @@ -2630,7 +2630,6 @@ def _update_title_position(self, renderer):
2630
2630
Update the title position based on the bounding box enclosing
2631
2631
all the ticklabels and x-axis spine and xlabel...
2632
2632
"""
2633
-
2634
2633
if self ._autotitlepos is not None and not self ._autotitlepos :
2635
2634
_log .debug ('title position was updated manually, not adjusting' )
2636
2635
return
@@ -2653,7 +2652,7 @@ def _update_title_position(self, renderer):
2653
2652
else :
2654
2653
ax .apply_aspect ()
2655
2654
axs = axs + [ax ]
2656
- top = 0
2655
+ top = - np . Inf
2657
2656
for ax in axs :
2658
2657
if (ax .xaxis .get_ticks_position () in ['top' , 'unknown' ]
2659
2658
or ax .xaxis .get_label_position () == 'top' ):
@@ -2662,6 +2661,11 @@ def _update_title_position(self, renderer):
2662
2661
bb = ax .get_window_extent (renderer )
2663
2662
if bb is not None :
2664
2663
top = max (top , bb .ymax )
2664
+ if top < 0 :
2665
+ # the top of axes is not even on the figure, so don't try and
2666
+ # automatically place it.
2667
+ _log .debug ('top of axes not in the figure, so title not moved' )
2668
+ return
2665
2669
if title .get_window_extent (renderer ).ymin < top :
2666
2670
_ , y = self .transAxes .inverted ().transform ((0 , top ))
2667
2671
title .set_position ((x , y ))
Original file line number Diff line number Diff line change @@ -5544,6 +5544,19 @@ def test_title_xticks_top_both():
5544
5544
assert ax .title .get_position ()[1 ] > 1.04
5545
5545
5546
5546
5547
+ def test_title_no_move_off_page ():
5548
+ # If an axes is off the figure (ie. if it is cropped during a save)
5549
+ # make sure that the automatic title repositioning does not get done.
5550
+ mpl .rcParams ['axes.titley' ] = None
5551
+ fig = plt .figure ()
5552
+ ax = fig .add_axes ([0.1 , - 0.5 , 0.8 , 0.2 ])
5553
+ ax .tick_params (axis = "x" ,
5554
+ bottom = True , top = True , labelbottom = True , labeltop = True )
5555
+ tt = ax .set_title ('Boo' )
5556
+ fig .canvas .draw ()
5557
+ assert tt .get_position ()[1 ] == 1.0
5558
+
5559
+
5547
5560
def test_offset_label_color ():
5548
5561
# Tests issue 6440
5549
5562
fig = plt .figure ()
You can’t perform that action at this time.
0 commit comments