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

Skip to content

Commit 608cc7f

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

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 13 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
"""
@@ -722,6 +734,7 @@ def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):
722734

723735
@docstring.dedent_interpd
724736
def annotate(self, text, xy, *args, **kwargs):
737+
print(text)
725738
a = mtext.Annotation(text, xy, *args, **kwargs)
726739
a.set_transform(mtransforms.IdentityTransform())
727740
if 'clip_on' in kwargs:

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)