Skip to content

Commit 4b3d513

Browse files
authored
Merge pull request matplotlib#22251 from anntzer/cbd
Colorbar docstring reorg
2 parents 6b4e640 + 17cc7fc commit 4b3d513

File tree

1 file changed

+64
-96
lines changed

1 file changed

+64
-96
lines changed

lib/matplotlib/colorbar.py

Lines changed: 64 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -29,98 +29,93 @@
2929

3030
_log = logging.getLogger(__name__)
3131

32-
_make_axes_param_doc = """
32+
_make_axes_kw_doc = """
3333
location : None or {'left', 'right', 'top', 'bottom'}
3434
The location, relative to the parent axes, where the colorbar axes
3535
is created. It also determines the *orientation* of the colorbar
3636
(colorbars on the left and right are vertical, colorbars at the top
3737
and bottom are horizontal). If None, the location will come from the
3838
*orientation* if it is set (vertical colorbars on the right, horizontal
3939
ones at the bottom), or default to 'right' if *orientation* is unset.
40+
4041
orientation : None or {'vertical', 'horizontal'}
4142
The orientation of the colorbar. It is preferable to set the *location*
4243
of the colorbar, as that also determines the *orientation*; passing
4344
incompatible values for *location* and *orientation* raises an exception.
45+
4446
fraction : float, default: 0.15
4547
Fraction of original axes to use for colorbar.
48+
4649
shrink : float, default: 1.0
4750
Fraction by which to multiply the size of the colorbar.
51+
4852
aspect : float, default: 20
4953
Ratio of long to short dimensions.
50-
"""
51-
_make_axes_other_param_doc = """
54+
5255
pad : float, default: 0.05 if vertical, 0.15 if horizontal
5356
Fraction of original axes between colorbar and new image axes.
57+
5458
anchor : (float, float), optional
5559
The anchor point of the colorbar axes.
5660
Defaults to (0.0, 0.5) if vertical; (0.5, 1.0) if horizontal.
61+
5762
panchor : (float, float), or *False*, optional
5863
The anchor point of the colorbar parent axes. If *False*, the parent
5964
axes' anchor will be unchanged.
6065
Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.
6166
"""
6267

6368
_colormap_kw_doc = """
64-
65-
============ ====================================================
66-
Property Description
67-
============ ====================================================
68-
*extend* {'neither', 'both', 'min', 'max'}
69-
If not 'neither', make pointed end(s) for out-of-
70-
range values. These are set for a given colormap
71-
using the colormap set_under and set_over methods.
72-
*extendfrac* {*None*, 'auto', length, lengths}
73-
If set to *None*, both the minimum and maximum
74-
triangular colorbar extensions with have a length of
75-
5% of the interior colorbar length (this is the
76-
default setting). If set to 'auto', makes the
77-
triangular colorbar extensions the same lengths as
78-
the interior boxes (when *spacing* is set to
79-
'uniform') or the same lengths as the respective
80-
adjacent interior boxes (when *spacing* is set to
81-
'proportional'). If a scalar, indicates the length
82-
of both the minimum and maximum triangular colorbar
83-
extensions as a fraction of the interior colorbar
84-
length. A two-element sequence of fractions may also
85-
be given, indicating the lengths of the minimum and
86-
maximum colorbar extensions respectively as a
87-
fraction of the interior colorbar length.
88-
*extendrect* bool
89-
If *False* the minimum and maximum colorbar extensions
90-
will be triangular (the default). If *True* the
91-
extensions will be rectangular.
92-
*spacing* {'uniform', 'proportional'}
93-
Uniform spacing gives each discrete color the same
94-
space; proportional makes the space proportional to
95-
the data interval.
96-
*ticks* *None* or list of ticks or Locator
97-
If None, ticks are determined automatically from the
98-
input.
99-
*format* None or str or Formatter
100-
If None, `~.ticker.ScalarFormatter` is used.
101-
If a format string is given, e.g., '%.3f', that is used.
102-
An alternative `~.ticker.Formatter` may be given instead.
103-
*drawedges* bool
104-
Whether to draw lines at color boundaries.
105-
*label* str
106-
The label on the colorbar's long axis.
107-
============ ====================================================
108-
109-
The following will probably be useful only in the context of
110-
indexed colors (that is, when the mappable has norm=NoNorm()),
111-
or other unusual circumstances.
112-
113-
============ ===================================================
114-
Property Description
115-
============ ===================================================
116-
*boundaries* None or a sequence
117-
*values* None or a sequence which must be of length 1 less
118-
than the sequence of *boundaries*. For each region
119-
delimited by adjacent entries in *boundaries*, the
120-
colormapped to the corresponding value in values
121-
will be used.
122-
============ ===================================================
123-
69+
extend : {'neither', 'both', 'min', 'max'}
70+
Make pointed end(s) for out-of-range values (unless 'neither'). These are
71+
set for a given colormap using the colormap set_under and set_over methods.
72+
73+
extendfrac : {*None*, 'auto', length, lengths}
74+
If set to *None*, both the minimum and maximum triangular colorbar
75+
extensions will have a length of 5% of the interior colorbar length (this
76+
is the default setting).
77+
78+
If set to 'auto', makes the triangular colorbar extensions the same lengths
79+
as the interior boxes (when *spacing* is set to 'uniform') or the same
80+
lengths as the respective adjacent interior boxes (when *spacing* is set to
81+
'proportional').
82+
83+
If a scalar, indicates the length of both the minimum and maximum
84+
triangular colorbar extensions as a fraction of the interior colorbar
85+
length. A two-element sequence of fractions may also be given, indicating
86+
the lengths of the minimum and maximum colorbar extensions respectively as
87+
a fraction of the interior colorbar length.
88+
89+
extendrect : bool
90+
If *False* the minimum and maximum colorbar extensions will be triangular
91+
(the default). If *True* the extensions will be rectangular.
92+
93+
spacing : {'uniform', 'proportional'}
94+
For discrete colorbars (`.BoundaryNorm` or contours), 'uniform' gives each
95+
color the same space; 'proportional' makes the space proportional to the
96+
data interval.
97+
98+
ticks : None or list of ticks or Locator
99+
If None, ticks are determined automatically from the input.
100+
101+
format : None or str or Formatter
102+
If None, `~.ticker.ScalarFormatter` is used.
103+
Format strings, e.g., ``"%4.2e"`` or ``"{x:.2e}"``, are supported.
104+
An alternative `~.ticker.Formatter` may be given instead.
105+
106+
drawedges : bool
107+
Whether to draw lines at color boundaries.
108+
109+
label : str
110+
The label on the colorbar's long axis.
111+
112+
boundaries, values : None or a sequence
113+
If unset, the colormap will be displayed on a 0-1 scale.
114+
If sequences, *values* must have a length 1 less than *boundaries*. For
115+
each region delimited by adjacent entries in *boundaries*, the color mapped
116+
to the corresponding value in values will be used.
117+
Normally only useful for indexed colors (i.e. ``norm=NoNorm()``) or other
118+
unusual circumstances.
124119
"""
125120

126121
docstring.interpd.update(colorbar_doc="""
@@ -161,7 +156,6 @@
161156
Additional keyword arguments are of two kinds:
162157
163158
axes properties:
164-
%s
165159
%s
166160
colorbar properties:
167161
%s
@@ -189,9 +183,8 @@
189183
However this has negative consequences in other circumstances, e.g. with
190184
semi-transparent images (alpha < 1) and colorbar extensions; therefore, this
191185
workaround is not used by default (see issue #1188).
192-
""" % (textwrap.indent(_make_axes_param_doc, " "),
193-
textwrap.indent(_make_axes_other_param_doc, " "),
194-
_colormap_kw_doc))
186+
""" % (textwrap.indent(_make_axes_kw_doc, " "),
187+
textwrap.indent(_colormap_kw_doc, " ")))
195188

196189

197190
def _set_ticks_on_axis_warn(*args, **kwargs):
@@ -278,6 +271,7 @@ def get_subplotspec(self):
278271
return ss
279272

280273

274+
@docstring.Substitution(_colormap_kw_doc)
281275
class Colorbar:
282276
r"""
283277
Draw a colorbar in an existing axes.
@@ -330,32 +324,14 @@ class Colorbar:
330324
alpha : float
331325
The colorbar transparency between 0 (transparent) and 1 (opaque).
332326
333-
values, boundaries
334-
If unset, the colormap will be displayed on a 0-1 scale.
335-
336327
orientation : {'vertical', 'horizontal'}
337328
338329
ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
339330
340-
extend : {'neither', 'both', 'min', 'max'}
341-
342-
spacing : {'uniform', 'proportional'}
343-
344-
ticks : `~matplotlib.ticker.Locator` or array-like of float
345-
346-
format : str or `~matplotlib.ticker.Formatter`
347-
If string, it supports '%' operator and `str.format` formats:
348-
e.g. ``"%4.2e"`` or ``"{x:.2e}"``.
349-
350331
drawedges : bool
351332
352333
filled : bool
353-
354-
extendfrac
355-
356-
extendrec
357-
358-
label : str
334+
%s
359335
"""
360336

361337
n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize
@@ -1375,7 +1351,7 @@ def _normalize_location_orientation(location, orientation):
13751351
return loc_settings
13761352

13771353

1378-
@docstring.Substitution(_make_axes_param_doc, _make_axes_other_param_doc)
1354+
@docstring.Substitution(_make_axes_kw_doc)
13791355
def make_axes(parents, location=None, orientation=None, fraction=0.15,
13801356
shrink=1.0, aspect=20, **kwargs):
13811357
"""
@@ -1397,10 +1373,6 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
13971373
kwargs : dict
13981374
The reduced keyword dictionary to be passed when creating the colorbar
13991375
instance.
1400-
1401-
Other Parameters
1402-
----------------
1403-
%s
14041376
"""
14051377
loc_settings = _normalize_location_orientation(location, orientation)
14061378
# put appropriate values into the kwargs dict for passing back to
@@ -1481,7 +1453,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14811453
return cax, kwargs
14821454

14831455

1484-
@docstring.Substitution(_make_axes_param_doc, _make_axes_other_param_doc)
1456+
@docstring.Substitution(_make_axes_kw_doc)
14851457
def make_axes_gridspec(parent, *, location=None, orientation=None,
14861458
fraction=0.15, shrink=1.0, aspect=20, **kwargs):
14871459
"""
@@ -1516,10 +1488,6 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
15161488
kwargs : dict
15171489
The reduced keyword dictionary to be passed when creating the colorbar
15181490
instance.
1519-
1520-
Other Parameters
1521-
----------------
1522-
%s
15231491
"""
15241492

15251493
loc_settings = _normalize_location_orientation(location, orientation)

0 commit comments

Comments
 (0)