Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 899af8e

Browse files
committed
Reorganize colorbar docstrings.
- Figure.colorbar and pyplot.colorbar can use the docstring (no need to restate the signatures, IPython/pydoc/sphinx does that for you). - Deprecate some docstrings that exist as globals at the module level. - Clarify what happens when `cax` and `ax` are both given (we can always emit a warning and deprecate that behavior later).
1 parent f6ff8db commit 899af8e

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

doc/api/api_changes_3.4/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ Deprecations
44
``dpi_cor`` property of `.FancyArrowPatch`
55
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66
This parameter is considered internal and deprecated.
7+
8+
Colorbar docstrings
9+
~~~~~~~~~~~~~~~~~~~
10+
The following globals in :mod:`matplotlib.colorbar` are deprecated:
11+
``colorbar_doc``, ``colormap_kw_doc``, ``make_axes_kw_doc``.

lib/matplotlib/colorbar.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@
8484
axes' anchor will be unchanged.
8585
Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.
8686
"""
87-
make_axes_kw_doc = _make_axes_param_doc + _make_axes_other_param_doc
8887

89-
colormap_kw_doc = """
88+
_colormap_kw_doc = """
9089
9190
============ ====================================================
9291
Property Description
@@ -149,18 +148,9 @@
149148
150149
"""
151150

152-
colorbar_doc = """
153-
151+
docstring.interpd.update(colorbar_doc="""
154152
Add a colorbar to a plot.
155153
156-
Function signatures for the :mod:`~matplotlib.pyplot` interface; all
157-
but the first are also method signatures for the `~.Figure.colorbar` method::
158-
159-
colorbar(**kwargs)
160-
colorbar(mappable, **kwargs)
161-
colorbar(mappable, cax=cax, **kwargs)
162-
colorbar(mappable, ax=ax, **kwargs)
163-
164154
Parameters
165155
----------
166156
mappable
@@ -179,9 +169,8 @@
179169
Axes into which the colorbar will be drawn.
180170
181171
ax : `~matplotlib.axes.Axes`, list of Axes, optional
182-
Parent axes from which space for a new colorbar axes will be stolen.
183-
If a list of axes is given they will all be resized to make room for the
184-
colorbar axes.
172+
One or more parent axes from which space for a new colorbar axes will be
173+
stolen, if *cax* is None. This has no effect if *cax* is set.
185174
186175
use_gridspec : bool, optional
187176
If *cax* is ``None``, a new *cax* is created as an instance of Axes. If
@@ -198,6 +187,7 @@
198187
Additional keyword arguments are of two kinds:
199188
200189
axes properties:
190+
%s
201191
%s
202192
colorbar properties:
203193
%s
@@ -225,10 +215,12 @@
225215
However this has negative consequences in other circumstances, e.g. with
226216
semi-transparent images (alpha < 1) and colorbar extensions; therefore, this
227217
workaround is not used by default (see issue #1188).
218+
""" % (_make_axes_param_doc, _make_axes_other_param_doc, _colormap_kw_doc))
228219

229-
""" % (make_axes_kw_doc, colormap_kw_doc)
230-
231-
docstring.interpd.update(colorbar_doc=colorbar_doc)
220+
# Deprecated since 3.4.
221+
colorbar_doc = docstring.interpd.params["colorbar_doc"]
222+
colormap_kw_doc = _colormap_kw_doc
223+
make_axes_kw_doc = _make_axes_param_doc + _make_axes_other_param_doc
232224

233225

234226
def _set_ticks_on_axis_warn(*args, **kw):

lib/matplotlib/figure.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,12 +2315,7 @@ def savefig(self, fname, *, transparent=None, **kwargs):
23152315

23162316
@docstring.dedent_interpd
23172317
def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
2318-
"""
2319-
Create a colorbar for a ScalarMappable instance, *mappable*.
2320-
2321-
Documentation for the pyplot thin wrapper:
2322-
%(colorbar_doc)s
2323-
"""
2318+
"""%(colorbar_doc)s"""
23242319
if ax is None:
23252320
ax = self.gca()
23262321

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,7 @@ def _setup_pyplot_info_docstrings():
21722172
## Plotting part 1: manually generated functions and wrappers ##
21732173

21742174

2175+
@_copy_docstring_and_deprecators(Figure.colorbar)
21752176
def colorbar(mappable=None, cax=None, ax=None, **kw):
21762177
if mappable is None:
21772178
mappable = gci()
@@ -2184,7 +2185,6 @@ def colorbar(mappable=None, cax=None, ax=None, **kw):
21842185
ax = gca()
21852186
ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kw)
21862187
return ret
2187-
colorbar.__doc__ = matplotlib.colorbar.colorbar_doc
21882188

21892189

21902190
def clim(vmin=None, vmax=None):

0 commit comments

Comments
 (0)