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

Skip to content

Commit 0e8027e

Browse files
committed
Added ax kwarg to pyplot.colorbar and Figure.colorbar
svn path=/trunk/matplotlib/; revision=3999
1 parent 87374d4 commit 0e8027e

5 files changed

Lines changed: 30 additions & 17 deletions

File tree

API_CHANGES

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
Changed cbook.reversed so it yields a tuple rather than a
1+
Added ax kwarg to pyplot.colorbar and Figure.colorbar so that
2+
one can specify the axes object from which space for the colorbar
3+
is to be taken, if one does not want to make the colorbar axes
4+
manually.
5+
6+
Changed cbook.reversed so it yields a tuple rather than a
27
(index, tuple). This agrees with the python reversed builtin,
3-
and cbook only defines reversed if python doesnt provide the
8+
and cbook only defines reversed if python doesnt provide the
49
builtin.
510

611
Made skiprows=1 the default on csv2rec

CHANGELOG

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2007-10-24 Added ax kwarg to Figure.colorbar and pyplot.colorbar - EF
2+
13
2007-10-19 Removed a gsave/grestore pair surrounding _draw_ps, which
24
was causing a loss graphics state info (see "EPS output
35
problem - scatter & edgecolors" on mpl-dev, 2007-10-29)
@@ -12,7 +14,7 @@
1214
unit/ellipse_compare.py to compare spline with vertex
1315
approx for both aspects. JDH
1416

15-
2007-10-05 remove generator expressions from texmanager and mpltraits.
17+
2007-10-05 remove generator expressions from texmanager and mpltraits.
1618
generator expressions are not supported by python-2.3 - DSD
1719

1820
2007-10-01 Made matplotlib.use() raise an exception if called after

lib/matplotlib/colorbar.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,27 @@
7070
colorbar_doc = '''
7171
Add a colorbar to a plot.
7272
73-
Function signatures:
73+
Function signatures for the pyplot interface; all but the first are
74+
also method signatures for the Figure.colorbar method:
7475
7576
colorbar(**kwargs)
76-
7777
colorbar(mappable, **kwargs)
78+
colorbar(mappable, cax=cax, **kwargs)
79+
colorbar(mappable, ax=ax, **kwargs)
80+
81+
arguments:
82+
mappable: the image, ContourSet, etc. to which the colorbar applies;
83+
this argument is mandatory for the Figure.colorbar
84+
method but optional for the pyplot.colorbar function,
85+
which sets the default to the current image.
7886
79-
colorbar(mappable, cax, **kwargs)
87+
keyword arguments:
88+
cax: None | axes object into which the colorbar will be drawn
89+
ax: None | parent axes object from which space for a new
90+
colorbar axes will be stolen
8091
81-
The optional arguments mappable and cax may be included in the kwargs;
82-
they are image, ContourSet, etc. to which the colorbar applies, and
83-
the axes object in which the colorbar will be drawn. Defaults are
84-
the current image and a new axes object created next to that image
85-
after resizing the image.
8692
87-
kwargs are in two groups:
93+
**kwargs are in two groups:
8894
axes properties:
8995
%s
9096
colorbar properties:

lib/matplotlib/figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,9 @@ def savefig(self, *args, **kwargs):
769769

770770
self.canvas.print_figure(*args, **kwargs)
771771

772-
def colorbar(self, mappable, cax=None, **kw):
773-
orientation = kw.get('orientation', 'vertical')
774-
ax = self.gca()
772+
def colorbar(self, mappable, cax=None, ax=None, **kw):
773+
if ax is None:
774+
ax = self.gca()
775775
if cax is None:
776776
cax, kw = cbar.make_axes(ax, **kw)
777777
cb = cbar.Colorbar(cax, mappable, **kw)

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,10 +1080,10 @@ def colormaps():
10801080

10811081

10821082
from matplotlib.colorbar import colorbar_doc
1083-
def colorbar(mappable = None, cax=None,**kw):
1083+
def colorbar(mappable=None, cax=None, ax=None, **kw):
10841084
if mappable is None:
10851085
mappable = gci()
1086-
ret = gcf().colorbar(mappable, cax = cax, **kw)
1086+
ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw)
10871087
draw_if_interactive()
10881088
return ret
10891089
colorbar.__doc__ = colorbar_doc

0 commit comments

Comments
 (0)