Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7d2b5e1

Browse filesBrowse files
committed
fixed contour to handle changes in cmap, etc
svn path=/trunk/matplotlib/; revision=884
1 parent 0082677 commit 7d2b5e1
Copy full SHA for 7d2b5e1

File tree

Expand file treeCollapse file tree

5 files changed

+32
-9
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+32
-9
lines changed

‎CHANGELOG

Copy file name to clipboardExpand all lines: CHANGELOG
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
New entries should be added at the top
22

3+
4+
2005-01-24 Fixed contour wto work w/ interactive changes in colormaps,
5+
clim, etc - JDH
6+
7+
===============================================================
8+
39
2005-01-21 matplotlib-0.71 released
410

511
2005-01-21 Refactored numerix to solve vexing namespace issues - JDH

‎examples/contour_demo2.py

Copy file name to clipboardExpand all lines: examples/contour_demo2.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
im = imshow(Z2-Z1, interpolation='bilinear', cmap=cm.gray)
1212
levels, colls = contour(Z2-Z1, linewidths=2)
1313
colorbar()
14+
hot()
1415
savefig('test')
1516
show()
1617

‎lib/matplotlib/axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes.py
+23-7Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,22 @@ def contour(self, z,
985985
used for colorbar functionality
986986
"""
987987

988+
class ContourMappable(ScalarMappable):
989+
"""
990+
a class to allow contours to respond properly to change in cmaps, etc
991+
"""
992+
def __init__(self, levels, collections, norm=None, cmap=None):
993+
ScalarMappable.__init__(self, norm, cmap)
994+
self.levels = levels
995+
self.collections = collections
996+
997+
def changed(self):
998+
colors = [ (tuple(rgba),) for rgba in self.to_rgba(self.levels)]
999+
for color, collection in zip(colors, self.collections):
1000+
collection.set_color(color)
1001+
ScalarMappable.changed(self)
1002+
1003+
9881004
if colors is not None and cmap is not None:
9891005
raise RuntimeError('Either colors or cmap must be None')
9901006
if origin is None: origin = rcParams['image.origin']
@@ -1049,7 +1065,8 @@ def autolev(N):
10491065

10501066

10511067
Nlev = len(lev)
1052-
1068+
collections = []
1069+
10531070
if colors is not None:
10541071

10551072
if is_string_like(colors):
@@ -1064,7 +1081,7 @@ def autolev(N):
10641081
tcolors = [(colorConverter.to_rgba(c, alpha),) for c in colors]
10651082
mappable = None
10661083
else:
1067-
mappable = ScalarMappable(cmap=cmap)
1084+
mappable = ContourMappable(lev, collections, cmap=cmap)
10681085
mappable.set_array(z)
10691086
mappable.autoscale()
10701087
tcolors = [ (tuple(rgba),) for rgba in mappable.to_rgba(lev)]
@@ -1082,15 +1099,14 @@ def autolev(N):
10821099

10831100
args = zip(lev, tcolors, tlinewidths)
10841101

1085-
levels = []
1086-
collections = []
10871102

10881103
region = 0
1104+
levels = []
10891105
for level, color, width in args:
10901106
ntotal, nparts = _contour.GcInit1(x, y, reg, triangle, region, z, level)
1091-
np = zeros((nparts,), Int)
1092-
xp = zeros((ntotal, ), Float64)
1093-
yp = zeros((ntotal,), Float64)
1107+
np = zeros((nparts,), 'l')
1108+
xp = zeros((ntotal, ), 'd')
1109+
yp = zeros((ntotal,), 'd')
10941110
nlist = _contour.GcTrace(np, xp, yp)
10951111
#print min(ravel(triangle)), max(ravel(triangle))
10961112
col = LineCollection(nlist, colors=color, linewidths = width)

‎lib/matplotlib/cm.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cm.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def set_cmap(self, cmap):
447447
self.changed()
448448

449449
def set_norm(self, norm):
450-
'set the colormap for luminance data'
450+
'set the normalization instance'
451451
if norm is None: norm = colors.normalize()
452452
self.norm = norm
453453
self.changed()

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def set_linestyle(self, ls):
327327

328328
self._ls = dashes
329329

330-
def color(self, c):
330+
def set_color(self, c):
331331
"""
332332
Set the color(s) of the line collection. c can be a matplotlib color arg
333333
(all patches have same color), or a a sequence or rgba tuples; if it

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.