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

Skip to content

Commit 0953a50

Browse files
committed
Added norm support to contour and colorbar.
svn path=/trunk/matplotlib/; revision=1956
1 parent cbb83fe commit 0953a50

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

lib/matplotlib/contour.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ def __init__(self, ax, *args, **kwargs):
394394
self.extent = kwargs.get('extent', None)
395395
cmap = kwargs.get('cmap', None)
396396
self.colors = kwargs.get('colors', None)
397+
norm = kwargs.get('norm', None)
397398
self.clip_ends = kwargs.get('clip_ends', True)
398399
self.antialiased = kwargs.get('antialiased', True)
399400
self.nchunk = kwargs.get('nchunk', 0)
@@ -417,11 +418,12 @@ def __init__(self, ax, *args, **kwargs):
417418
self.cl = []
418419
self.cl_cvalues = []
419420

420-
ScalarMappable.__init__(self, cmap = cmap) # sets self.cmap;
421-
# default norm for now
421+
kw = {'cmap': cmap}
422+
if norm is not None:
423+
kw['norm'] = norm
424+
ScalarMappable.__init__(self, **kw) # sets self.cmap;
422425
self._process_colors()
423426

424-
425427
if self.filled:
426428
if self.linewidths is None:
427429
self.linewidths = 0.05 # Good default for Postscript.
@@ -453,7 +455,6 @@ def __init__(self, ax, *args, **kwargs):
453455

454456
if level < 0.0 and self.monochrome:
455457
col.set_linestyle((0, (6.,6.)),)
456-
#print "setting dashed"
457458
col.set_label(str(level)) # only for self-documentation
458459
self.ax.add_collection(col)
459460
self.collections.append(col)
@@ -687,6 +688,11 @@ def _process_linewidths(self):
687688
* cmap = None: a cm Colormap instance from matplotlib.cm.
688689
- if cmap == None and colors == None, a default Colormap is used.
689690
691+
* norm = None: a matplotlib.colors.normalize instance for
692+
scaling data values to colors.
693+
- if norm == None, and colors == None, the default
694+
linear scaling is used.
695+
690696
* origin = None: 'upper'|'lower'|'image'|None.
691697
If 'image', the rc value for image.origin will be used.
692698
If None (default), the first value of Z will correspond

lib/matplotlib/figure.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,8 @@ def colorbar(self, mappable, cax=None,
656656
"""
657657
Create a colorbar for mappable image
658658
659-
mappable is the cm.ScalarMappable instance that you want to
660-
colorbar to apply to, eg an Image as returned by imshow or a
659+
mappable is the cm.ScalarMappable instance that you want the
660+
colorbar to apply to, e.g. an Image as returned by imshow or a
661661
PatchCollection as returned by scatter or pcolor.
662662
663663
tickfmt is a format string to format the colorbar ticks
@@ -750,7 +750,13 @@ def colorbar(self, mappable, cax=None,
750750
args = (transpose(Y), transpose(C), transpose(X), clevs)
751751
else:
752752
args = (C, Y, X, clevs)
753-
kw = {'cmap':cmap}
753+
#If colors were listed in the original mappable, then
754+
# let contour handle them the same way.
755+
colors = getattr(mappable, 'colors', None)
756+
if colors is not None:
757+
kw = {'colors': colors}
758+
else:
759+
kw = {'cmap':cmap, 'norm':norm}
754760
if isContourSet and not mappable.filled:
755761
CS = cax.contour(*args, **kw)
756762
colls = mappable.collections
@@ -826,7 +832,7 @@ def figaspect(arg):
826832
Create a figure with specified aspect ratio. If arg is a number,
827833
use that aspect ratio. If arg is an array, figaspect will
828834
determine the width and height for a figure that would fit array
829-
preserving aspcect ratio. The figure width, height in inches are
835+
preserving aspect ratio. The figure width, height in inches are
830836
returned. Be sure to create an axes with equal with and height,
831837
eg
832838

0 commit comments

Comments
 (0)