Revision: 8355
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8355&view=rev
Author:   efiring
Date:     2010-06-01 00:31:42 +0000 (Tue, 01 Jun 2010)

Log Message:
-----------
Colormap.__call__: override existing alpha only if alpha is specified.
Closes 2891982.  The color for masked data is still handled differently;
this may need to be changed.

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

Modified: trunk/matplotlib/lib/matplotlib/colors.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/colors.py   2010-05-31 23:05:55 UTC (rev 
8354)
+++ trunk/matplotlib/lib/matplotlib/colors.py   2010-06-01 00:31:42 UTC (rev 
8355)
@@ -482,7 +482,7 @@
         self._isinit = False
 
 
-    def __call__(self, X, alpha=1.0, bytes=False):
+    def __call__(self, X, alpha=None, bytes=False):
         """
         *X* is either a scalar or an array (of any dimension).
         If scalar, a tuple of rgba values is returned, otherwise
@@ -490,18 +490,12 @@
         are integers, then they are used as indices into the array.
         If they are floating point, then they must be in the
         interval (0.0, 1.0).
-        Alpha must be a scalar.
+        Alpha must be a scalar between 0 and 1, or None.
         If bytes is False, the rgba values will be floats on a
         0-1 scale; if True, they will be uint8, 0-255.
         """
 
         if not self._isinit: self._init()
-        alpha = min(alpha, 1.0) # alpha must be between 0 and 1
-        alpha = max(alpha, 0.0)
-        self._lut[:-1,-1] = alpha  # Don't assign global alpha to i_bad;
-                                   # it would defeat the purpose of the
-                                   # default behavior, which is to not
-                                   # show anything where data are missing.
         mask_bad = None
         if not cbook.iterable(X):
             vtype = 'scalar'
@@ -532,7 +526,17 @@
         if bytes:
             lut = (self._lut * 255).astype(np.uint8)
         else:
-            lut = self._lut
+            lut = self._lut.copy()
+
+        if alpha is not None:
+            alpha = min(alpha, 1.0) # alpha must be between 0 and 1
+            alpha = max(alpha, 0.0)
+            lut[:-1,-1] = alpha  # Don't assign global alpha to i_bad;
+                                       # it would defeat the purpose of the
+                                       # default behavior, which is to not
+                                       # show anything where data are missing.
+
+
         rgba = np.empty(shape=xa.shape+(4,), dtype=lut.dtype)
         lut.take(xa, axis=0, mode='clip', out=rgba)
                     #  twice as fast as lut[xa];


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

------------------------------------------------------------------------------

_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to