SourceForge logo
SourceForge logo
Menu

matplotlib-checkins

From: <ef...@us...> - 2009年10月23日 02:44:44
Revision: 7902
 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7902&view=rev
Author: efiring
Date: 2009年10月23日 02:44:32 +0000 (2009年10月23日)
Log Message:
-----------
Fixed two bugs involving reversal of colormaps.
Modified Paths:
--------------
 trunk/matplotlib/lib/matplotlib/cm.py
Modified: trunk/matplotlib/lib/matplotlib/cm.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cm.py	2009年10月22日 13:46:08 UTC (rev 7901)
+++ trunk/matplotlib/lib/matplotlib/cm.py	2009年10月23日 02:44:32 UTC (rev 7902)
@@ -19,11 +19,20 @@
 # reverse all the colormaps.
 # reversed colormaps have '_r' appended to the name.
 
+def _reverser(f):
+ def freversed(x):
+ return f(1-x)
+ return freversed
+
 def revcmap(data):
 data_r = {}
 for key, val in data.iteritems():
 if callable(val):
- valnew = lambda x: 1 - val(x)
+ valnew = _reverser(val)
+ # This doesn't work: lambda x: val(1-x)
+ # The same "val" (the first one) is used
+ # each time, so the colors are identical
+ # and the result is shades of gray.
 else:
 valnew = [(1.0 - a, b, c) for a, b, c in reversed(val)]
 data_r[key] = valnew
@@ -43,13 +52,15 @@
 cmap_d[cmapname_r] = colors.LinearSegmentedColormap(
 cmapname_r, datad[cmapname_r], LUTSIZE)
 else:
- datad[cmapname] = list(cmapspec)
- datad[cmapname_r] = list(datad[cmapname])
- datad[cmapname_r].reverse()
+ revspec = list(reversed(cmapspec))
+ if len(revspec[0]) == 2: # e.g., (1, (1.0, 0.0, 1.0))
+ revspec = [(1.0 - a, b) for a, b in revspec]
+ datad[cmapname_r] = revspec
+
 cmap_d[cmapname] = colors.LinearSegmentedColormap.from_list(
- cmapname, datad[cmapname], LUTSIZE)
+ cmapname, cmapspec, LUTSIZE)
 cmap_d[cmapname_r] = colors.LinearSegmentedColormap.from_list(
- cmapname_r, datad[cmapname_r], LUTSIZE)
+ cmapname_r, revspec, LUTSIZE)
 
 locals().update(cmap_d)
 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /