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

Skip to content

Commit f5c85d8

Browse files
committed
contour: support vmin, vmax kwargs for consistency with pcolor etc.
This changeset also simplifies and clarifies the vmin, vmax explanation and handling for pcolor and pcolormesh.
1 parent 9cba6fb commit f5c85d8

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

CHANGELOG

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
2012-08-05 When a norm is passed to contourf, either or both of the
2+
vmin, vmax attributes of that norm are now respected.
3+
Formerly they were respected only if both were
4+
specified. In addition, vmin and/or vmax can now
5+
be passed to contourf directly as kwargs. - EF
6+
17
2012-07-24 Contourf handles the extend kwarg by mapping the extended
28
ranges outside the normed 0-1 range so that they are
39
handled by colormap colors determined by the set_under
410
and set_over methods. Previously the extended ranges
511
were mapped to 0 or 1 so that the "under" and "over"
6-
colormap colors were ignored. - EF
12+
colormap colors were ignored. This change also increases
13+
slightly the color contrast for a given set of contour
14+
levels. - EF
715

816
2012-06-24 Make use of mathtext in tick labels configurable - DSD
917

lib/matplotlib/axes.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,7 +3754,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
37543754
linestyles=linestyles, label=label)
37553755
self.add_collection(coll)
37563756
coll.update(kwargs)
3757-
3757+
37583758
if len(x) > 0:
37593759
minx = min( x )
37603760
maxx = max( x )
@@ -6955,16 +6955,18 @@ def pcolor(self, *args, **kwargs):
69556955
A :class:`matplotlib.colors.Colormap` instance. If *None*, use
69566956
rc settings.
69576957
6958-
norm: [ *None* | Normalize ]
6958+
*norm*: [ *None* | Normalize ]
69596959
An :class:`matplotlib.colors.Normalize` instance is used
69606960
to scale luminance data to 0,1. If *None*, defaults to
69616961
:func:`normalize`.
69626962
69636963
*vmin*/*vmax*: [ *None* | scalar ]
69646964
*vmin* and *vmax* are used in conjunction with *norm* to
6965-
normalize luminance data. If either are *None*, the min
6966-
and max of the color array *C* is used. If you pass a
6967-
*norm* instance, *vmin* and *vmax* will be ignored.
6965+
normalize luminance data. If either is *None*, it
6966+
is autoscaled to the respective min or max
6967+
of the color array *C*. If not *None*, *vmin* or
6968+
*vmax* passed in here override any pre-existing values
6969+
supplied in the *norm* instance.
69686970
69696971
*shading*: [ 'flat' | 'faceted' ]
69706972
If 'faceted', a black grid is drawn around each rectangle; if
@@ -7121,10 +7123,8 @@ def pcolor(self, *args, **kwargs):
71217123
if norm is not None: assert(isinstance(norm, mcolors.Normalize))
71227124
collection.set_cmap(cmap)
71237125
collection.set_norm(norm)
7124-
if vmin is not None or vmax is not None:
7125-
collection.set_clim(vmin, vmax)
7126-
else:
7127-
collection.autoscale_None()
7126+
collection.set_clim(vmin, vmax)
7127+
collection.autoscale_None()
71287128
self.grid(False)
71297129

71307130
x = X.compressed()
@@ -7167,9 +7167,11 @@ def pcolormesh(self, *args, **kwargs):
71677167
71687168
*vmin*/*vmax*: [ *None* | scalar ]
71697169
*vmin* and *vmax* are used in conjunction with *norm* to
7170-
normalize luminance data. If either are *None*, the min
7171-
and max of the color array *C* is used. If you pass a
7172-
*norm* instance, *vmin* and *vmax* will be ignored.
7170+
normalize luminance data. If either is *None*, it
7171+
is autoscaled to the respective min or max
7172+
of the color array *C*. If not *None*, *vmin* or
7173+
*vmax* passed in here override any pre-existing values
7174+
supplied in the *norm* instance.
71737175
71747176
*shading*: [ 'flat' | 'gouraud' ]
71757177
'flat' indicates a solid color for each quad. When
@@ -7235,10 +7237,8 @@ def pcolormesh(self, *args, **kwargs):
72357237
if norm is not None: assert(isinstance(norm, mcolors.Normalize))
72367238
collection.set_cmap(cmap)
72377239
collection.set_norm(norm)
7238-
if vmin is not None or vmax is not None:
7239-
collection.set_clim(vmin, vmax)
7240-
else:
7241-
collection.autoscale_None()
7240+
collection.set_clim(vmin, vmax)
7241+
collection.autoscale_None()
72427242

72437243
self.grid(False)
72447244

lib/matplotlib/contour.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ def __init__(self, ax, *args, **kwargs):
742742
cmap = kwargs.get('cmap', None)
743743
self.colors = kwargs.get('colors', None)
744744
norm = kwargs.get('norm', None)
745+
vmin = kwargs.get('vmin', None)
746+
vmax = kwargs.get('vmax', None)
745747
self.extend = kwargs.get('extend', 'neither')
746748
self.antialiased = kwargs.get('antialiased', None)
747749
if self.antialiased is None and self.filled:
@@ -789,7 +791,11 @@ def __init__(self, ax, *args, **kwargs):
789791
kw = {'cmap': cmap}
790792
if norm is not None:
791793
kw['norm'] = norm
792-
cm.ScalarMappable.__init__(self, **kw) # sets self.cmap;
794+
cm.ScalarMappable.__init__(self, **kw) # sets self.cmap, norm if needed;
795+
if vmin is not None:
796+
self.norm.vmin = vmin
797+
if vmax is not None:
798+
self.norm.vmax = vmax
793799
self._process_colors()
794800

795801
self.allsegs, self.allkinds = self._get_allsegs_and_allkinds()
@@ -1488,6 +1494,12 @@ def _initialize_x_y(self, z):
14881494
scaling data values to colors. If *norm* is *None* and
14891495
*colors* is *None*, the default linear scaling is used.
14901496
1497+
*vmin*/*vmax*: [ *None* | scalar ]
1498+
If not *None*, either or both of these values will be
1499+
supplied to the :class:`matplotlib.colors.Normalize`
1500+
instance, overriding the default color scaling based on
1501+
*levels*.
1502+
14911503
*levels*: [level0, level1, ..., leveln]
14921504
A list of floating point numbers indicating the level
14931505
curves to draw; eg to draw just the zero contour pass

0 commit comments

Comments
 (0)