Skip to content

Commit 03a3e37

Browse files
committed
subplots.py docs cleanup
1 parent 94b6022 commit 03a3e37

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

proplot/subplots.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ def __setitem__(self, key, value):
101101
raise LookupError('subplot_grid is immutable.')
102102

103103
def __getitem__(self, key):
104-
"""If an integer is passed, the item is returned, and if a slice is
105-
passed, an `subplot_grid` of the items is returned. You can also use 2d
106-
indexing, and the corresponding axes in the axes grid will be chosen.
104+
"""If an integer is passed, the item is returned. If a slice is passed,
105+
a `subplot_grid` of the items is returned. You can also use 2D
106+
indexing, and the corresponding axes in the `subplot_grid` will be
107+
chosen.
107108
108109
Example
109110
-------
@@ -180,11 +181,11 @@ def __getitem__(self, key):
180181

181182
def __getattr__(self, attr):
182183
"""
183-
If the attribute is *callable*, returns a dummy function that loops
184+
If the attribute is *callable*, return a dummy function that loops
184185
through each identically named method, calls them in succession, and
185186
returns a tuple of the results. This lets you call arbitrary methods
186-
on multiple axes at once! If the `subplot_grid` has length ``1``,
187-
just returns the single result. If the attribute is *not callable*,
187+
on multiple axes at once! If the `subplot_grid` has length ``1``, the
188+
single result is returned. If the attribute is *not callable*,
188189
returns a tuple of attributes for every object in the list.
189190
190191
Example
@@ -242,9 +243,13 @@ def shape(self):
242243

243244
class SubplotSpec(mgridspec.SubplotSpec):
244245
"""
245-
Adds two helper methods to `~matplotlib.gridspec.SubplotSpec` that return
246-
the geometry *excluding* rows and columns allocated for spaces.
246+
Matplotlib `~matplotlib.gridspec.SubplotSpec` subclass that adds
247+
some helpful methods.
247248
"""
249+
def __repr__(self):
250+
nrows, ncols, row1, row2, col1, col2 = self.get_rows_columns()
251+
return f'SubplotSpec({nrows}, {ncols}; {row1}:{row2}, {col1}:{col2})'
252+
248253
def get_active_geometry(self):
249254
"""Returns the number of rows, number of columns, and 1d subplot
250255
location indices, ignoring rows and columns allocated for spaces."""
@@ -271,16 +276,19 @@ def get_active_rows_columns(self):
271276

272277
class GridSpec(mgridspec.GridSpec):
273278
"""
274-
`~matplotlib.gridspec.GridSpec` generalization that allows for grids with
275-
*variable spacing* between successive rows and columns of axes.
276-
279+
Matplotlib `~matplotlib.gridspec.GridSpec` subclass that allows for grids
280+
with variable spacing between successive rows and columns of axes.
277281
Accomplishes this by actually drawing ``nrows*2 + 1`` and ``ncols*2 + 1``
278282
`~matplotlib.gridspec.GridSpec` rows and columns, setting `wspace`
279283
and `hspace` to ``0``, and masking out every other row and column
280284
of the `~matplotlib.gridspec.GridSpec`, so they act as "spaces".
281285
These "spaces" are then allowed to vary in width using the builtin
282286
`width_ratios` and `height_ratios` properties.
283287
"""
288+
def __repr__(self): # do not show width and height ratios
289+
nrows, ncols = self.get_geometry()
290+
return f'GridSpec({nrows}, {ncols})'
291+
284292
def __init__(self, figure, nrows=1, ncols=1, **kwargs):
285293
"""
286294
Parameters
@@ -446,15 +454,17 @@ def get_active_geometry(self):
446454

447455
def update(self, **kwargs):
448456
"""
449-
Updates the width ratios, height ratios, gridspec margins, and spacing
450-
allocated between subplot rows and columns.
451-
457+
Update the gridspec with arbitrary initialization keyword arguments
458+
then *apply* those updates to every figure using this gridspec.
452459
The default `~matplotlib.gridspec.GridSpec.update` tries to update
453460
positions for axes on all active figures -- but this can fail after
454461
successive figure edits if it has been removed from the figure
455-
manager. So, we explicitly require that the gridspec is dedicated to
456-
a particular `~matplotlib.figure.Figure` instance, and just edit axes
457-
positions for axes on that instance.
462+
manager. ProPlot insists one gridspec per figure.
463+
464+
Parameters
465+
----------
466+
**kwargs
467+
Valid initialization keyword arguments. See `GridSpec`.
458468
"""
459469
# Convert spaces to ratios
460470
wratios, hratios, kwargs = self._spaces_as_ratios(**kwargs)
@@ -1341,7 +1351,7 @@ def _align_axislabels(self, b=True):
13411351
})
13421352

13431353
def _align_labels(self, renderer):
1344-
"""Adjusts position of row and column labels, and aligns figure super
1354+
"""Adjust the position of row and column labels, and align figure super
13451355
title accounting for figure margins and axes and figure panels."""
13461356
# Offset using tight bounding boxes
13471357
# TODO: Super labels fail with popup backend!! Fix this
@@ -1656,7 +1666,7 @@ def colorbar(
16561666
**kwargs
16571667
):
16581668
"""
1659-
Draws a colorbar along the left, right, bottom, or top side
1669+
Draw a colorbar along the left, right, bottom, or top side
16601670
of the figure, centered between the leftmost and rightmost (or
16611671
topmost and bottommost) main axes.
16621672
@@ -1773,7 +1783,7 @@ def legend(
17731783
**kwargs
17741784
):
17751785
"""
1776-
Draws a legend along the left, right, bottom, or top side of the
1786+
Draw a legend along the left, right, bottom, or top side of the
17771787
figure, centered between the leftmost and rightmost (or
17781788
topmost and bottommost) main axes.
17791789
@@ -2032,8 +2042,8 @@ def _axes_dict(naxs, value, kw=False, default=None):
20322042
# Verify numbers
20332043
if {*range(1, naxs + 1)} != {*kwargs.keys()}:
20342044
raise ValueError(
2035-
f'Have {naxs} axes, but {value} has properties for axes '
2036-
+ ', '.join(repr(i) for i in sorted(kwargs.keys())) + '.'
2045+
f'Have {naxs} axes, but {value!r} has properties for axes '
2046+
+ ', '.join(map(repr, sorted(kwargs))) + '.'
20372047
)
20382048
return kwargs
20392049

@@ -2053,8 +2063,9 @@ def subplots(
20532063
**kwargs
20542064
):
20552065
"""
2056-
Analogous to `matplotlib.pyplot.subplots`, creates a figure with a single
2057-
axes or arbitrary grids of axes, any of which can be map projections.
2066+
Create a figure with a single axes or arbitrary grid of axes, analogous
2067+
to `matplotlib.pyplot.subplots`. The axes can have arbitrary map
2068+
projections.
20582069
20592070
Parameters
20602071
----------

0 commit comments

Comments
 (0)