Revision: 6790
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6790&view=rev
Author:   jdh2358
Date:     2009-01-16 17:06:38 +0000 (Fri, 16 Jan 2009)

Log Message:
-----------
added custom colormap from list func

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/lib/matplotlib/colors.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2009-01-16 16:25:28 UTC (rev 6789)
+++ trunk/matplotlib/CHANGELOG  2009-01-16 17:06:38 UTC (rev 6790)
@@ -1,3 +1,7 @@
+2009-11-16 Added helper function LinearSegmentedColormap.from_list to
+           facilitate building simple custom colomaps.  See
+           examples/pylab_examples/custom_cmap_fromlist.py - JDH
+
 2009-01-16 Applied Michiel's patch for macosx backend to fix rounding
            bug. Closed sf bug 2508440 - JSW
 

Modified: trunk/matplotlib/lib/matplotlib/colors.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/colors.py   2009-01-16 16:25:28 UTC (rev 
6789)
+++ trunk/matplotlib/lib/matplotlib/colors.py   2009-01-16 17:06:38 UTC (rev 
6790)
@@ -611,7 +611,27 @@
         self._isinit = True
         self._set_extremes()
 
+    @staticmethod
+    def from_list(name, colors, N=256):
+        """
+        Make a linear segmented colormap with *name* from a sequence
+        of *colors* which evenly transitions from colors[0] at val=1
+        to colors[-1] at val=1.  N is the number of rgb quantization
+        levels.
+        """
 
+        ncolors = len(colors)
+        vals = np.linspace(0., 1., ncolors)
+
+        cdict = dict(red=[], green=[], blue=[])
+        for val, color in zip(vals, colors):
+            r,g,b = colorConverter.to_rgb(color)
+            cdict['red'].append((val, r, r))
+            cdict['green'].append((val, g, g))
+            cdict['blue'].append((val, b, b))
+
+        return LinearSegmentedColormap(name, cdict, N)
+
 class ListedColormap(Colormap):
     """Colormap object generated from a list of colors.
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to