|
From: <ef...@us...> - 2010-06-01 01:03:12
|
Revision: 8356
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8356&view=rev
Author: efiring
Date: 2010-06-01 01:03:06 +0000 (Tue, 01 Jun 2010)
Log Message:
-----------
colors.py: more improvement in alpha handling for over, under, and bad values
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/colors.py
Modified: trunk/matplotlib/lib/matplotlib/colors.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/colors.py 2010-06-01 00:31:42 UTC (rev 8355)
+++ trunk/matplotlib/lib/matplotlib/colors.py 2010-06-01 01:03:06 UTC (rev 8356)
@@ -526,17 +526,21 @@
if bytes:
lut = (self._lut * 255).astype(np.uint8)
else:
- lut = self._lut.copy()
+ lut = self._lut.copy() # Don't let alpha modify original _lut.
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.
+ if (lut[-1] == 0).all():
+ lut[:-1, -1] = alpha
+ # All zeros is taken as a flag for the default bad
+ # color, which is no color--fully transparent. We
+ # don't want to override this.
+ else:
+ lut[:,-1] = alpha
+ # If the bad value is set to have a color, then we
+ # override its alpha just as for any other value.
-
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];
@@ -546,20 +550,20 @@
rgba = tuple(rgba[0,:])
return rgba
- def set_bad(self, color = 'k', alpha = 1.0):
+ def set_bad(self, color = 'k', alpha = None):
'''Set color to be used for masked values.
'''
self._rgba_bad = colorConverter.to_rgba(color, alpha)
if self._isinit: self._set_extremes()
- def set_under(self, color = 'k', alpha = 1.0):
+ def set_under(self, color = 'k', alpha = None):
'''Set color to be used for low out-of-range values.
Requires norm.clip = False
'''
self._rgba_under = colorConverter.to_rgba(color, alpha)
if self._isinit: self._set_extremes()
- def set_over(self, color = 'k', alpha = 1.0):
+ def set_over(self, color = 'k', alpha = None):
'''Set color to be used for high out-of-range values.
Requires norm.clip = False
'''
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|