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.