@@ -30,9 +30,18 @@ class GridSpecBase:
3030
3131 def __init__ (self , nrows , ncols , height_ratios = None , width_ratios = None ):
3232 """
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.
3645 """
3746 self ._nrows , self ._ncols = nrows , ncols
3847 self .set_height_ratios (height_ratios )
@@ -57,39 +66,85 @@ def get_geometry(self):
5766 return self ._nrows , self ._ncols
5867
5968 def get_subplot_params (self , figure = None ):
69+ # Must be implemented in subclasses
6070 pass
6171
6272 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+ """
6484 loc1 , loc2 = loc
6585 subplotspec = self [loc1 :loc1 + rowspan , loc2 :loc2 + colspan ]
6686 return subplotspec
6787
6888 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+ """
6995 if width_ratios is not None and len (width_ratios ) != self ._ncols :
7096 raise ValueError ('Expected the given number of width ratios to '
7197 'match the number of columns of the grid' )
7298 self ._col_width_ratios = width_ratios
7399
74100 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+ """
75106 return self ._col_width_ratios
76107
77108 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+ """
78115 if height_ratios is not None and len (height_ratios ) != self ._nrows :
79116 raise ValueError ('Expected the given number of height ratios to '
80117 'match the number of rows of the grid' )
81118 self ._row_height_ratios = height_ratios
82119
83120 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+ """
84126 return self ._row_height_ratios
85127
86128 def get_grid_positions (self , fig , raw = False ):
87129 """
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.
90142
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.
93148 """
94149 nrows , ncols = self .get_geometry ()
95150
@@ -192,11 +247,8 @@ def __init__(self, nrows, ncols, figure=None,
192247
193248 Parameters
194249 ----------
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.
200252
201253 figure : `~.figure.Figure`, optional
202254
@@ -213,11 +265,15 @@ def __init__(self, nrows, ncols, figure=None,
213265 The amount of height reserved for space between subplots,
214266 expressed as a fraction of the average axis height.
215267
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.
218272
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.
221277
222278 Notes
223279 -----
0 commit comments