@@ -30,9 +30,18 @@ class GridSpecBase:
30
30
31
31
def __init__ (self , nrows , ncols , height_ratios = None , width_ratios = None ):
32
32
"""
33
- The number of rows and number of columns of the grid need to
34
- be set. Optionally, the ratio of heights and widths of rows and
35
- columns can be specified.
33
+ Parameters
34
+ ----------
35
+ nrows, ncols : int
36
+ The number of rows and columns of the grid.
37
+ width_ratios : array-like of length *ncols*, optional
38
+ Defines the relative widths of the columns. Each column gets a
39
+ relative width of ``width_ratios[i] / sum(width_ratios)``.
40
+ If not given, all columns will have the same width.
41
+ height_ratios : array-like of length *nrows*, optional
42
+ Defines the relative heights of the rows. Each column gets a
43
+ relative height of ``height_ratios[i] / sum(height_ratios)``.
44
+ If not given, all rows will have the same height.
36
45
"""
37
46
self ._nrows , self ._ncols = nrows , ncols
38
47
self .set_height_ratios (height_ratios )
@@ -57,39 +66,85 @@ def get_geometry(self):
57
66
return self ._nrows , self ._ncols
58
67
59
68
def get_subplot_params (self , figure = None ):
69
+ # Must be implemented in subclasses
60
70
pass
61
71
62
72
def new_subplotspec (self , loc , rowspan = 1 , colspan = 1 ):
63
- """Create and return a `.SubplotSpec` instance."""
73
+ """
74
+ Create and return a `.SubplotSpec` instance.
75
+
76
+ Parameters
77
+ ----------
78
+ loc : (int, int)
79
+ The position of the subplot in the grid as
80
+ ``(row_index, column_index)``.
81
+ rowspan, colspan : int, default: 1
82
+ The number of rows and columns the subplot should span in the grid.
83
+ """
64
84
loc1 , loc2 = loc
65
85
subplotspec = self [loc1 :loc1 + rowspan , loc2 :loc2 + colspan ]
66
86
return subplotspec
67
87
68
88
def set_width_ratios (self , width_ratios ):
89
+ """
90
+ Set the relative widths of the columns.
91
+
92
+ *width_ratios* must be of length *ncols*. Each column gets a relative
93
+ width of ``width_ratios[i] / sum(width_ratios)``.
94
+ """
69
95
if width_ratios is not None and len (width_ratios ) != self ._ncols :
70
96
raise ValueError ('Expected the given number of width ratios to '
71
97
'match the number of columns of the grid' )
72
98
self ._col_width_ratios = width_ratios
73
99
74
100
def get_width_ratios (self ):
101
+ """
102
+ Return the width ratios.
103
+
104
+ This is *None* if no width ratios have been set explicitly.
105
+ """
75
106
return self ._col_width_ratios
76
107
77
108
def set_height_ratios (self , height_ratios ):
109
+ """
110
+ Set the relative heights of the rows.
111
+
112
+ *height_ratios* must be of length *nrows*. Each row gets a relative
113
+ height of ``height_ratios[i] / sum(height_ratios)``.
114
+ """
78
115
if height_ratios is not None and len (height_ratios ) != self ._nrows :
79
116
raise ValueError ('Expected the given number of height ratios to '
80
117
'match the number of rows of the grid' )
81
118
self ._row_height_ratios = height_ratios
82
119
83
120
def get_height_ratios (self ):
121
+ """
122
+ Return the height ratios.
123
+
124
+ This is *None* if no height ratios have been set explicitly.
125
+ """
84
126
return self ._row_height_ratios
85
127
86
128
def get_grid_positions (self , fig , raw = False ):
87
129
"""
88
- Return lists of bottom and top position of rows, left and
89
- right positions of columns.
130
+ Return the positions of the grid cells in figure coordinates.
131
+
132
+ Parameters
133
+ ----------
134
+ fig : `~matplotlib.figure.Figure`
135
+ The figure the grid should be applied to. The subplot parameters
136
+ (margins and spacing between subplots) are taken from *fig*.
137
+ raw : bool, default: False
138
+ If *True*, the subplot parameters of the figure are not taken
139
+ into account. The grid spans the range [0, 1] in both directions
140
+ without margins and there is no space between grid cells. This is
141
+ used for constrained_layout.
90
142
91
- If raw=True, then these are all in units relative to the container
92
- with no margins. (used for constrained_layout).
143
+ Returns
144
+ -------
145
+ bottoms, tops, lefts, rights : array
146
+ The bottom, top, left, right positions of the grid cells in
147
+ figure coordinates.
93
148
"""
94
149
nrows , ncols = self .get_geometry ()
95
150
@@ -192,11 +247,8 @@ def __init__(self, nrows, ncols, figure=None,
192
247
193
248
Parameters
194
249
----------
195
- nrows : int
196
- Number of rows in grid.
197
-
198
- ncols : int
199
- Number or columns in grid.
250
+ nrows, ncols : int
251
+ The number of rows and columns of the grid.
200
252
201
253
figure : `~.figure.Figure`, optional
202
254
@@ -213,11 +265,15 @@ def __init__(self, nrows, ncols, figure=None,
213
265
The amount of height reserved for space between subplots,
214
266
expressed as a fraction of the average axis height.
215
267
216
- width_ratios : length *ncols* iterable, optional
217
- Width ratios of the columns.
268
+ width_ratios : array-like of length *ncols*, optional
269
+ Defines the relative widths of the columns. Each column gets a
270
+ relative width of ``width_ratios[i] / sum(width_ratios)``.
271
+ If not given, all columns will have the same width.
218
272
219
- height_ratios : length *nrows* iterable, optional
220
- Height ratios of the rows.
273
+ height_ratios : array-like of length *nrows*, optional
274
+ Defines the relative heights of the rows. Each column gets a
275
+ relative height of ``height_ratios[i] / sum(height_ratios)``.
276
+ If not given, all rows will have the same height.
221
277
222
278
Notes
223
279
-----
0 commit comments