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