@@ -34,77 +34,62 @@ def _get_top(tight_bbox, axes_bbox):
34
34
return tight_bbox .ymax - axes_bbox .ymax
35
35
36
36
37
- def auto_adjust_subplotpars (fig , renderer ,
38
- nrows_ncols ,
39
- num1num2_list ,
40
- subplot_list ,
41
- ax_bbox_list = None ,
42
- pad = 1.08 , h_pad = None , w_pad = None ,
43
- rect = None ):
37
+ def auto_adjust_subplotpars (
38
+ fig , renderer , nrows_ncols , num1num2_list , subplot_list ,
39
+ ax_bbox_list = None , pad = 1.08 , h_pad = None , w_pad = None , rect = None ):
44
40
"""
45
- Return a dictionary of subplot parameters so that spacing between
46
- subplots are adjusted. Note that this function ignore geometry
47
- information of subplot itself, but uses what is given by
48
- *nrows_ncols* and *num1num2_list* parameteres. Also, the results could be
49
- incorrect if some subplots have ``adjustable=datalim``.
50
-
51
- Parameters:
52
-
53
- nrows_ncols
54
- number of rows and number of columns of the grid.
55
-
56
- num1num2_list
57
- list of numbers specifying the area occupied by the subplot
58
-
59
- subplot_list
60
- list of subplots that will be used to calcuate optimal subplot_params.
61
-
41
+ Return a dict of subplot parameters to adjust spacing between subplots.
42
+
43
+ Note that this function ignores geometry information of subplot
44
+ itself, but uses what is given by the *nrows_ncols* and *num1num2_list*
45
+ parameters. Also, the results could be incorrect if some subplots have
46
+ ``adjustable=datalim``.
47
+
48
+ Parameters
49
+ ----------
50
+ nrows_ncols : Tuple[int, int]
51
+ Number of rows and number of columns of the grid.
52
+ num1num2_list : List[int]
53
+ List of numbers specifying the area occupied by the subplot
54
+ subplot_list : list of subplots
55
+ List of subplots that will be used to calculate optimal subplot_params.
62
56
pad : float
63
- padding between the figure edge and the edges of subplots, as a fraction
64
- of the font- size.
57
+ Padding between the figure edge and the edges of subplots, as a
58
+ fraction of the font size.
65
59
h_pad, w_pad : float
66
- padding (height/width) between edges of adjacent subplots.
67
- Defaults to `pad_inches`.
68
-
69
- rect
70
- [left, bottom, right, top] in normalized (0, 1) figure coordinates.
60
+ Padding (height/width) between edges of adjacent subplots, as a
61
+ fraction of the font size. Defaults to *pad*.
62
+ rect : Tuple[float, float, float, float]
63
+ [left, bottom, right, top] in normalized (0, 1) figure coordinates.
71
64
"""
72
65
rows , cols = nrows_ncols
73
66
74
- pad_inches = pad * FontProperties (
75
- size = rcParams ["font.size" ]).get_size_in_points () / 72.
76
-
67
+ font_size_inches = (
68
+ FontProperties ( size = rcParams ["font.size" ]).get_size_in_points () / 72 )
69
+ pad_inches = pad * font_size_inches
77
70
if h_pad is not None :
78
- vpad_inches = h_pad * FontProperties (
79
- size = rcParams ["font.size" ]).get_size_in_points () / 72.
71
+ vpad_inches = h_pad * font_size_inches
80
72
else :
81
73
vpad_inches = pad_inches
82
74
83
75
if w_pad is not None :
84
- hpad_inches = w_pad * FontProperties (
85
- size = rcParams ["font.size" ]).get_size_in_points () / 72.
76
+ hpad_inches = w_pad * font_size_inches
86
77
else :
87
78
hpad_inches = pad_inches
88
79
89
- if len (subplot_list ) == 0 :
90
- raise RuntimeError ("" )
91
-
92
- if len (num1num2_list ) != len (subplot_list ):
93
- raise RuntimeError ("" )
80
+ if len (num1num2_list ) != len (subplot_list ) or len (subplot_list ) == 0 :
81
+ raise ValueError
94
82
95
83
if rect is None :
96
- margin_left = None
97
- margin_bottom = None
98
- margin_right = None
99
- margin_top = None
84
+ margin_left = margin_bottom = margin_right = margin_top = None
100
85
else :
101
86
margin_left , margin_bottom , _right , _top = rect
102
87
if _right :
103
- margin_right = 1. - _right
88
+ margin_right = 1 - _right
104
89
else :
105
90
margin_right = None
106
91
if _top :
107
- margin_top = 1. - _top
92
+ margin_top = 1 - _top
108
93
else :
109
94
margin_top = None
110
95
@@ -262,42 +247,34 @@ def get_subplotspec_list(axes_list, grid_spec=None):
262
247
def get_tight_layout_figure (fig , axes_list , subplotspec_list , renderer ,
263
248
pad = 1.08 , h_pad = None , w_pad = None , rect = None ):
264
249
"""
265
- Return subplot parameters for tight-layouted-figure with specified
266
- padding.
267
-
268
- Parameters:
269
-
270
- *fig* : figure instance
271
-
272
- *axes_list* : a list of axes
273
-
274
- *subplotspec_list* : a list of subplotspec associated with each
275
- axes in axes_list
276
-
277
- *renderer* : renderer instance
278
-
279
- *pad* : float
280
- padding between the figure edge and the edges of subplots,
281
- as a fraction of the font-size.
282
-
283
- *h_pad*, *w_pad* : float
284
- padding (height/width) between edges of adjacent subplots.
285
- Defaults to `pad_inches`.
286
-
287
- *rect* : if rect is given, it is interpreted as a rectangle
288
- (left, bottom, right, top) in the normalized figure
289
- coordinate that the whole subplots area (including
290
- labels) will fit into. Default is (0, 0, 1, 1).
250
+ Return subplot parameters for tight-layouted-figure with specified padding.
251
+
252
+ Parameters
253
+ ----------
254
+ fig : Figure
255
+ axes_list : list of Axes
256
+ subplotspec_list : list of `~.SubplotSpec`
257
+ The subplotspecs of each axes.
258
+ renderer : renderer
259
+ pad : float
260
+ Padding between the figure edge and the edges of subplots, as a
261
+ fraction of the font size.
262
+ h_pad, w_pad : float
263
+ Padding (height/width) between edges of adjacent subplots. Defaults to
264
+ *pad_inches*.
265
+ rect : Tuple[float, float, float, float], optional
266
+ (left, bottom, right, top) rectangle in normalized figure coordinates
267
+ that the whole subplots area (including labels) will fit into.
268
+ Defaults to using the entire figure.
291
269
"""
292
270
293
271
subplot_list = []
294
272
nrows_list = []
295
273
ncols_list = []
296
274
ax_bbox_list = []
297
275
298
- subplot_dict = {} # multiple axes can share
299
- # same subplot_interface (e.g., axes_grid1). Thus
300
- # we need to join them together.
276
+ subplot_dict = {} # Multiple axes can share same subplot_interface (e.g.,
277
+ # axes_grid1); thus we need to join them together.
301
278
302
279
subplotspec_list2 = []
303
280
0 commit comments