File tree 2 files changed +36
-0
lines changed
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -2990,6 +2990,12 @@ def _update_title_position(self, renderer):
2990
2990
if bb is None :
2991
2991
bb = ax .get_window_extent (renderer )
2992
2992
top = max (top , bb .ymax )
2993
+ if title .get_text ():
2994
+ ax .yaxis .get_tightbbox (renderer ) # update offsetText
2995
+ if ax .yaxis .offsetText .get_text ():
2996
+ bb = ax .yaxis .offsetText .get_tightbbox (renderer )
2997
+ if bb .intersection (title .get_tightbbox (renderer ), bb ):
2998
+ top = bb .ymax
2993
2999
if top < 0 :
2994
3000
# the top of Axes is not even on the figure, so don't try and
2995
3001
# automatically place it.
Original file line number Diff line number Diff line change @@ -6121,6 +6121,36 @@ def test_title_xticks_top_both():
6121
6121
assert ax .title .get_position ()[1 ] > 1.04
6122
6122
6123
6123
6124
+ @pytest .mark .parametrize (
6125
+ 'left, center' , [
6126
+ ('left' , '' ),
6127
+ ('' , 'center' ),
6128
+ ('left' , 'center' )
6129
+ ], ids = [
6130
+ 'left title moved' ,
6131
+ 'center title kept' ,
6132
+ 'both titles aligned'
6133
+ ]
6134
+ )
6135
+ def test_title_above_offset (left , center ):
6136
+ # Test that title moves if overlaps with yaxis offset text.
6137
+ mpl .rcParams ['axes.titley' ] = None
6138
+ fig , ax = plt .subplots ()
6139
+ ax .set_ylim (1e11 )
6140
+ ax .set_title (left , loc = 'left' )
6141
+ ax .set_title (center )
6142
+ fig .draw_without_rendering ()
6143
+ if left and not center :
6144
+ assert ax ._left_title .get_position ()[1 ] > 1.0
6145
+ elif not left and center :
6146
+ assert ax .title .get_position ()[1 ] == 1.0
6147
+ else :
6148
+ yleft = ax ._left_title .get_position ()[1 ]
6149
+ ycenter = ax .title .get_position ()[1 ]
6150
+ assert yleft > 1.0
6151
+ assert ycenter == yleft
6152
+
6153
+
6124
6154
def test_title_no_move_off_page ():
6125
6155
# If an axes is off the figure (ie. if it is cropped during a save)
6126
6156
# make sure that the automatic title repositioning does not get done.
You can’t perform that action at this time.
0 commit comments