18
18
import numpy as np
19
19
20
20
from matplotlib import _api , artist as martist
21
- from matplotlib ._tight_layout import get_renderer
22
21
import matplotlib .transforms as mtransforms
23
22
import matplotlib ._layoutgrid as mlayoutgrid
24
23
@@ -74,8 +73,6 @@ def do_constrained_layout(fig, h_pad, w_pad,
74
73
fig : Figure
75
74
``Figure`` instance to do the layout in.
76
75
77
- renderer : Renderer
78
- Renderer to use.
79
76
80
77
h_pad, w_pad : float
81
78
Padding around the axes elements in figure-normalized units.
@@ -92,7 +89,6 @@ def do_constrained_layout(fig, h_pad, w_pad,
92
89
layoutgrid : private debugging structure
93
90
"""
94
91
95
- renderer = get_renderer (fig )
96
92
# make layoutgrid tree...
97
93
layoutgrids = make_layoutgrids (fig , None )
98
94
if not layoutgrids ['hasgrids' ]:
@@ -109,9 +105,9 @@ def do_constrained_layout(fig, h_pad, w_pad,
109
105
110
106
# make margins for all the axes and subfigures in the
111
107
# figure. Add margins for colorbars...
112
- make_layout_margins (layoutgrids , fig , renderer , h_pad = h_pad ,
108
+ make_layout_margins (layoutgrids , fig , h_pad = h_pad ,
113
109
w_pad = w_pad , hspace = hspace , wspace = wspace )
114
- make_margin_suptitles (layoutgrids , fig , renderer , h_pad = h_pad ,
110
+ make_margin_suptitles (layoutgrids , fig , h_pad = h_pad ,
115
111
w_pad = w_pad )
116
112
117
113
# if a layout is such that a columns (or rows) margin has no
@@ -123,7 +119,7 @@ def do_constrained_layout(fig, h_pad, w_pad,
123
119
layoutgrids [fig ].update_variables ()
124
120
125
121
if check_no_collapsed_axes (layoutgrids , fig ):
126
- reposition_axes (layoutgrids , fig , renderer , h_pad = h_pad ,
122
+ reposition_axes (layoutgrids , fig , h_pad = h_pad ,
127
123
w_pad = w_pad , hspace = hspace , wspace = wspace )
128
124
else :
129
125
_api .warn_external ('constrained_layout not applied because '
@@ -283,7 +279,7 @@ def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,
283
279
return margin
284
280
285
281
286
- def make_layout_margins (layoutgrids , fig , renderer , * , w_pad = 0 , h_pad = 0 ,
282
+ def make_layout_margins (layoutgrids , fig , * , w_pad = 0 , h_pad = 0 ,
287
283
hspace = 0 , wspace = 0 ):
288
284
"""
289
285
For each axes, make a margin between the *pos* layoutbox and the
@@ -294,7 +290,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
294
290
"""
295
291
for sfig in fig .subfigs : # recursively make child panel margins
296
292
ss = sfig ._subplotspec
297
- make_layout_margins (layoutgrids , sfig , renderer ,
293
+ make_layout_margins (layoutgrids , sfig ,
298
294
w_pad = w_pad , h_pad = h_pad ,
299
295
hspace = hspace , wspace = wspace )
300
296
@@ -314,7 +310,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
314
310
315
311
margin = get_margin_from_padding (ax , w_pad = w_pad , h_pad = h_pad ,
316
312
hspace = hspace , wspace = wspace )
317
- pos , bbox = get_pos_and_bbox (ax , renderer )
313
+ pos , bbox = get_pos_and_bbox (ax )
318
314
# the margin is the distance between the bounding box of the axes
319
315
# and its position (plus the padding from above)
320
316
margin ['left' ] += pos .x0 - bbox .x0
@@ -331,7 +327,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
331
327
# colorbars can be child of more than one subplot spec:
332
328
cbp_rspan , cbp_cspan = get_cb_parent_spans (cbax )
333
329
loc = cbax ._colorbar_info ['location' ]
334
- cbpos , cbbbox = get_pos_and_bbox (cbax , renderer )
330
+ cbpos , cbbbox = get_pos_and_bbox (cbax )
335
331
if loc == 'right' :
336
332
if cbp_cspan .stop == ss .colspan .stop :
337
333
# only increase if the colorbar is on the right edge
@@ -367,7 +363,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
367
363
layoutgrids [gs ].edit_outer_margin_mins (margin , ss )
368
364
369
365
370
- def make_margin_suptitles (layoutgrids , fig , renderer , * , w_pad = 0 , h_pad = 0 ):
366
+ def make_margin_suptitles (layoutgrids , fig , * , w_pad = 0 , h_pad = 0 ):
371
367
# Figure out how large the suptitle is and make the
372
368
# top level figure margin larger.
373
369
@@ -380,29 +376,29 @@ def make_margin_suptitles(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0):
380
376
w_pad_local = padbox .width
381
377
382
378
for sfig in fig .subfigs :
383
- make_margin_suptitles (layoutgrids , sfig , renderer ,
379
+ make_margin_suptitles (layoutgrids , sfig ,
384
380
w_pad = w_pad , h_pad = h_pad )
385
381
386
382
if fig ._suptitle is not None and fig ._suptitle .get_in_layout ():
387
383
p = fig ._suptitle .get_position ()
388
384
if getattr (fig ._suptitle , '_autopos' , False ):
389
385
fig ._suptitle .set_position ((p [0 ], 1 - h_pad_local ))
390
- bbox = inv_trans_fig (fig ._suptitle .get_tightbbox (renderer ))
386
+ bbox = inv_trans_fig (fig ._suptitle .get_tightbbox ())
391
387
layoutgrids [fig ].edit_margin_min ('top' , bbox .height + 2 * h_pad )
392
388
393
389
if fig ._supxlabel is not None and fig ._supxlabel .get_in_layout ():
394
390
p = fig ._supxlabel .get_position ()
395
391
if getattr (fig ._supxlabel , '_autopos' , False ):
396
392
fig ._supxlabel .set_position ((p [0 ], h_pad_local ))
397
- bbox = inv_trans_fig (fig ._supxlabel .get_tightbbox (renderer ))
393
+ bbox = inv_trans_fig (fig ._supxlabel .get_tightbbox ())
398
394
layoutgrids [fig ].edit_margin_min ('bottom' ,
399
395
bbox .height + 2 * h_pad )
400
396
401
397
if fig ._supylabel is not None and fig ._supylabel .get_in_layout ():
402
398
p = fig ._supylabel .get_position ()
403
399
if getattr (fig ._supylabel , '_autopos' , False ):
404
400
fig ._supylabel .set_position ((w_pad_local , p [1 ]))
405
- bbox = inv_trans_fig (fig ._supylabel .get_tightbbox (renderer ))
401
+ bbox = inv_trans_fig (fig ._supylabel .get_tightbbox ())
406
402
layoutgrids [fig ].edit_margin_min ('left' , bbox .width + 2 * w_pad )
407
403
408
404
@@ -523,14 +519,14 @@ def get_cb_parent_spans(cbax):
523
519
return rowspan , colspan
524
520
525
521
526
- def get_pos_and_bbox (ax , renderer ):
522
+ def get_pos_and_bbox (ax ):
527
523
"""
528
524
Get the position and the bbox for the axes.
529
525
530
526
Parameters
531
527
----------
532
528
ax
533
- renderer
529
+
534
530
535
531
Returns
536
532
-------
@@ -543,15 +539,15 @@ def get_pos_and_bbox(ax, renderer):
543
539
pos = ax .get_position (original = True )
544
540
# pos is in panel co-ords, but we need in figure for the layout
545
541
pos = pos .transformed (fig .transSubfigure - fig .transFigure )
546
- tightbbox = martist ._get_tightbbox_for_layout_only (ax , renderer )
542
+ tightbbox = martist ._get_tightbbox_for_layout_only (ax )
547
543
if tightbbox is None :
548
544
bbox = pos
549
545
else :
550
546
bbox = tightbbox .transformed (fig .transFigure .inverted ())
551
547
return pos , bbox
552
548
553
549
554
- def reposition_axes (layoutgrids , fig , renderer , * ,
550
+ def reposition_axes (layoutgrids , fig , * ,
555
551
w_pad = 0 , h_pad = 0 , hspace = 0 , wspace = 0 ):
556
552
"""
557
553
Reposition all the axes based on the new inner bounding box.
@@ -561,7 +557,7 @@ def reposition_axes(layoutgrids, fig, renderer, *,
561
557
bbox = layoutgrids [sfig ].get_outer_bbox ()
562
558
sfig ._redo_transform_rel_fig (
563
559
bbox = bbox .transformed (trans_fig_to_subfig ))
564
- reposition_axes (layoutgrids , sfig , renderer ,
560
+ reposition_axes (layoutgrids , sfig ,
565
561
w_pad = w_pad , h_pad = h_pad ,
566
562
wspace = wspace , hspace = hspace )
567
563
@@ -589,11 +585,11 @@ def reposition_axes(layoutgrids, fig, renderer, *,
589
585
offset = {'left' : 0 , 'right' : 0 , 'bottom' : 0 , 'top' : 0 }
590
586
for nn , cbax in enumerate (ax ._colorbars [::- 1 ]):
591
587
if ax == cbax ._colorbar_info ['parents' ][0 ]:
592
- reposition_colorbar (layoutgrids , cbax , renderer ,
588
+ reposition_colorbar (layoutgrids , cbax ,
593
589
offset = offset )
594
590
595
591
596
- def reposition_colorbar (layoutgrids , cbax , renderer , * , offset = None ):
592
+ def reposition_colorbar (layoutgrids , cbax , * , offset = None ):
597
593
"""
598
594
Place the colorbar in its new place.
599
595
@@ -602,7 +598,6 @@ def reposition_colorbar(layoutgrids, cbax, renderer, *, offset=None):
602
598
cbax : Axes
603
599
Axes for the colorbar
604
600
605
- renderer :
606
601
w_pad, h_pad : float
607
602
width and height padding (in fraction of figure)
608
603
hspace, wspace : float
@@ -629,7 +624,7 @@ def reposition_colorbar(layoutgrids, cbax, renderer, *, offset=None):
629
624
aspect = cbax ._colorbar_info ['aspect' ]
630
625
shrink = cbax ._colorbar_info ['shrink' ]
631
626
632
- cbpos , cbbbox = get_pos_and_bbox (cbax , renderer )
627
+ cbpos , cbbbox = get_pos_and_bbox (cbax )
633
628
634
629
# Colorbar gets put at extreme edge of outer bbox of the subplotspec
635
630
# It needs to be moved in by: 1) a pad 2) its "margin" 3) by
0 commit comments