@@ -2500,34 +2500,50 @@ def _update_title_position(self, renderer):
2500
2500
x , y = title .get_position ()
2501
2501
if not np .isclose (y , 1.0 ):
2502
2502
self ._autotitlepos = False
2503
- _log .debug ('not adjusting title pos because title was'
2503
+ _log .debug ('not adjusting title pos because a title was'
2504
2504
' already placed manually: %f' , y )
2505
2505
return
2506
2506
self ._autotitlepos = True
2507
2507
2508
+ ymax = - 10
2508
2509
for title in titles :
2509
2510
x , y0 = title .get_position ()
2510
- y = 1.0
2511
+ y = 1
2512
+ # need to start again in case of window resizing
2513
+ title .set_position ((x , 1.0 ))
2511
2514
# need to check all our twins too...
2512
2515
axs = self ._twinned_axes .get_siblings (self )
2513
2516
2517
+ top = 0 # the top of all the axes twinned with this axes...
2514
2518
for ax in axs :
2515
2519
try :
2516
2520
if (ax .xaxis .get_label_position () == 'top'
2517
2521
or ax .xaxis .get_ticks_position () == 'top' ):
2518
2522
bb = ax .xaxis .get_tightbbox (renderer )
2519
- top = bb .ymax
2520
- # we don't need to pad because the padding is already
2521
- # in __init__: titleOffsetTrans
2522
- yn = self .transAxes .inverted ().transform ((0. , top ))[1 ]
2523
- y = max (y , yn )
2523
+ else :
2524
+ bb = ax .get_window_extent (renderer )
2525
+ top = max (top , bb .ymax )
2524
2526
except AttributeError :
2525
- pass
2526
-
2527
- title .set_position ((x , y ))
2527
+ # this happens for an empty bb
2528
+ y = 1
2529
+ if title .get_window_extent (renderer ).ymin < top :
2530
+ y = self .transAxes .inverted ().transform (
2531
+ (0. , top ))[1 ]
2532
+ title .set_position ((x , y ))
2533
+ # emperically, this doesn't always get the min to top,
2534
+ # so we need to adjust again.
2535
+ if title .get_window_extent (renderer ).ymin < top :
2536
+ y = self .transAxes .inverted ().transform (
2537
+ (0. , 2 * top -
2538
+ title .get_window_extent (renderer ).ymin ))[1 ]
2539
+ title .set_position ((x , y ))
2540
+ ymax = max (y , ymax )
2541
+ for title in titles :
2542
+ # now line up all the titles at the highest baseline.
2543
+ x , y0 = title .get_position ()
2544
+ title .set_position ((x , ymax ))
2528
2545
2529
2546
# Drawing
2530
-
2531
2547
@allow_rasterization
2532
2548
def draw (self , renderer = None , inframe = False ):
2533
2549
"""Draw everything (plot lines, axes, labels)"""
@@ -4201,19 +4217,19 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4201
4217
if bb_xaxis :
4202
4218
bb .append (bb_xaxis )
4203
4219
4204
- self ._update_title_position (renderer )
4205
- bb .append (self .get_window_extent (renderer ))
4220
+ bb_yaxis = self .yaxis .get_tightbbox (renderer )
4221
+ if bb_yaxis :
4222
+ bb .append (bb_yaxis )
4206
4223
4224
+ self ._update_title_position (renderer )
4207
4225
if self .title .get_visible ():
4208
4226
bb .append (self .title .get_window_extent (renderer ))
4209
4227
if self ._left_title .get_visible ():
4210
4228
bb .append (self ._left_title .get_window_extent (renderer ))
4211
4229
if self ._right_title .get_visible ():
4212
4230
bb .append (self ._right_title .get_window_extent (renderer ))
4213
4231
4214
- bb_yaxis = self .yaxis .get_tightbbox (renderer )
4215
- if bb_yaxis :
4216
- bb .append (bb_yaxis )
4232
+ bb .append (self .get_window_extent (renderer ))
4217
4233
4218
4234
bbox_artists = bbox_extra_artists
4219
4235
if bbox_artists is None :
0 commit comments