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

Skip to content

Commit e7cb45e

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

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,21 @@ 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+
ax = kw.pop(ax)
431+
if ax is not None:
432+
warnings.warn('Supplied ax argument ignored')
433+
self.figure.colorbar(self, mappable, cax=cax, ax=self,
434+
use_gridspec=use_gridspec, **kw)
435+
421436
def inset_axes(self, bounds, *, transform=None, zorder=5,
422437
**kwargs):
423438
"""

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)