8000 ENH: add colorbar method to axes · matplotlib/matplotlib@6e896a7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e896a7

Browse files
committed
ENH: add colorbar method to axes
1 parent c574969 commit 6e896a7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ def legend(self, *args, **kwargs):
418418
def _remove_legend(self, legend):
419419
self.legend_ = None
420420

421+
@docstring.dedent_interpd
422+
def colorbar(self, mappable, cax=None, use_gridspec=True, **kw):
423+
"""
424+
Create a colorbar for a ScalarMappable instance, *mappable*, with the
425+
axes as the parent.
426+
427+
Documentation for the pyplot thin wrapper:
428+
%(colorbar_doc)s
429+
"""
430+
self.figure.colorbar(self, mappable, cax=None, ax=self,
431+
use_gridspec=True, **kw)
432+
421433
def inset_axes(self, bounds, *, transform=None, zorder=5,
422434
**kwargs):
423435
"""

lib/mpl_toolkits/axes_grid1/colorbar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
the :class:`~matplotlib.image.Image`,
110110
:class:`~matplotlib.contour.ContourSet`, etc. to
111111
which the colorbar applies; this argument is mandatory for the
112-
:meth:`~matplotlib.figure.Figure.colorbar` method but optional for the
112+
:meth:`~matplotlib.figure.Figure.colorbar`
113+
and :meth:`~matplotlib.axes.Axes.colorbar` methods but optional for the
113114
:func:`~matplotlib.pyplot.colorbar` function, which sets the
114115
default to the current image.
115116
@@ -119,7 +120,7 @@
119120
None | axes object into which the colorbar will be drawn
120121
*ax*
121122
None | parent axes object from which space for a new
122-
colorbar axes will be stolen
123+
colorbar axes will be stolen (ignored for `.axes.Axes.colorbar`)
123124
124125
125126
Additional keyword arguments are of two kinds:

0 commit comments

Comments
 (0)
0