@@ -2501,34 +2501,53 @@ 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 agin 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
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 = np .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
+ bt = title .get_window_extent (renderer )
2531
+ # need to do twice to get right for manual resizing
2532
+ for nn in range (1 ):
2533
+ dy = bt .ymin - top
2534
+ if dy < 0 :
2535
+ y = self .transAxes .inverted ().transform (
2536
+ (0. , top ))[1 ]
2537
+ title .set_position ((x , y ))
2538
+ bt = title .get_window_extent (renderer )
2539
+ dy = bt .ymin - top
2540
+ if dy < 0 :
2541
+ y = self .transAxes .inverted ().transform (
2542
+ (0. , top - dy ))[1 ]
2543
+ title .set_position ((x , y ))
2544
+ ymax = np .max ((y , ymax ))
2545
+ for title in titles :
2546
+ # now line up all the titles at the highest baseline.
2547
+ x , y0 = title .get_position ()
2548
+ title .set_position ((x , ymax ))
2529
2549
2530
2550
# Drawing
2531
-
2532
2551
@allow_rasterization
2533
2552
def draw (self , renderer = None , inframe = False ):
2534
2553
"""Draw everything (plot lines, axes, labels)"""
@@ -4200,19 +4219,19 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4200
4219
if bb_xaxis :
4201
4220
bb .append (bb_xaxis )
4202
4221
4203
- self ._update_title_position (renderer )
4204
- bb .append (self .get_window_extent (renderer ))
4222
+ bb_yaxis = self .yaxis .get_tightbbox (renderer )
4223
+ if bb_yaxis :
4224
+ bb .append (bb_yaxis )
4205
4225
4226
+ self ._update_title_position (renderer )
4206
4227
if self .title .get_visible ():
4207
4228
bb .append (self .title .get_window_extent (renderer ))
4208
4229
if self ._left_title .get_visible ():
4209
4230
bb .append (self ._left_title .get_window_extent (renderer ))
4210
4231
if self ._right_title .get_visible ():
4211
4232
bb .append (self ._right_title .get_window_extent (renderer ))
4212
4233
4213
- bb_yaxis = self .yaxis .get_tightbbox (renderer )
4214
- if bb_yaxis :
4215
- bb .append (bb_yaxis )
4234
+ bb .append (self .get_window_extent (renderer ))
4216
4235
4217
4236
bbox_artists = bbox_extra_artists
4218
4237
if bbox_artists is None :
0 commit comments