@@ -232,38 +232,42 @@ def _normalize(key, size, axis): # Includes last index.
232
232
233
233
class GridSpec (GridSpecBase ):
234
234
"""
235
- Specifies the geometry of the grid that a subplot can be placed in .
235
+ A grid layout to place subplots within a figure .
236
236
237
- The location of grid is determined by similar way as the SubplotParams.
237
+ The location of the grid cells is determined in a similar way to
238
+ `~.figure.SubplotParams` using *left*, *right*, *top*, *bottom*, *wspace*
239
+ and *hspace*.
238
240
"""
239
241
def __init__ (self , nrows , ncols , figure = None ,
240
242
left = None , bottom = None , right = None , top = None ,
241
243
wspace = None , hspace = None ,
242
244
width_ratios = None , height_ratios = None ):
243
245
"""
244
- The number of rows and number of columns of the grid need to be set.
245
- Optionally, the subplot layout parameters (e.g., left, right, etc.)
246
- can be tuned.
247
-
248
246
Parameters
249
247
----------
250
248
nrows, ncols : int
251
249
The number of rows and columns of the grid.
252
250
253
251
figure : `~.figure.Figure`, optional
252
+ Only used for constrained layout to create a proper layoutbox.
254
253
255
254
left, right, top, bottom : float, optional
256
255
Extent of the subplots as a fraction of figure width or height.
257
256
Left cannot be larger than right, and bottom cannot be larger than
258
- top.
257
+ top. If not given, the values will be inferred from a figure or
258
+ rcParams when necessary. See also `GridSpec.get_subplot_params`.
259
259
260
260
wspace : float, optional
261
261
The amount of width reserved for space between subplots,
262
262
expressed as a fraction of the average axis width.
263
+ If not given, the values will be inferred from a figure or
264
+ rcParams when necessary. See also `GridSpec.get_subplot_params`.
263
265
264
266
hspace : float, optional
265
267
The amount of height reserved for space between subplots,
266
268
expressed as a fraction of the average axis height.
269
+ If not given, the values will be inferred from a figure or
270
+ rcParams when necessary. See also `GridSpec.get_subplot_params`.
267
271
268
272
width_ratios : array-like of length *ncols*, optional
269
273
Defines the relative widths of the columns. Each column gets a
@@ -275,9 +279,6 @@ def __init__(self, nrows, ncols, figure=None,
275
279
relative height of ``height_ratios[i] / sum(height_ratios)``.
276
280
If not given, all rows will have the same height.
277
281
278
- Notes
279
- -----
280
- See `~.figure.SubplotParams` for descriptions of the layout parameters.
281
282
"""
282
283
self .left = left
283
284
self .bottom = bottom
@@ -320,7 +321,12 @@ def __setstate__(self, state):
320
321
321
322
def update (self , ** kwargs ):
322
323
"""
323
- Update the current values.
324
+ Update the subplot parameters of the grid.
325
+
326
+ Parameters:
327
+ ----------
328
+ left, right, top, bottom : float, optional
329
+ wspace, hspace : float, optional
324
330
325
331
Values set to None use the rcParams value.
326
332
"""
@@ -350,8 +356,13 @@ def update(self, **kwargs):
350
356
351
357
def get_subplot_params (self , figure = None ):
352
358
"""
353
- Return a dictionary of subplot layout parameters. The default
354
- parameters are from rcParams unless a figure attribute is set.
359
+ Return the `~.SubplotParams` for the GridSpec.
360
+
361
+ In order of precedence the values are taken from
362
+
363
+ - non-*None* attributes of the GridSpec
364
+ - the provided *figure*
365
+ - :rc:`figure.subplot.*`
355
366
"""
356
367
if figure is None :
357
368
kw = {k : rcParams ["figure.subplot." + k ] for k in self ._AllowedKeys }
@@ -364,6 +375,12 @@ def get_subplot_params(self, figure=None):
364
375
return subplotpars
365
376
366
377
def locally_modified_subplot_params (self ):
378
+ """
379
+ Return a list of the names of the subplot parameters explicitly set
380
+ in the GridSpec.
381
+
382
+ This is a subset of the attributes of `.SubplotParams`.
383
+ """
367
384
return [k for k in self ._AllowedKeys if getattr (self , k )]
368
385
369
386
def tight_layout (self , figure , renderer = None ,
0 commit comments