Skip to content

Commit 52ae800

Browse files
committed
Merged revisions 4318-4329 via svnmerge from
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r4325 | dsdale | 2007-11-15 16:23:27 -0500 (Thu, 15 Nov 2007) | 4 lines added npy.seterr(invalid='ignore') to beginning of axes.py, to silence repeated warnings created by finding extrema of arrays containing nans (discovered during calls to errorbar) ........ r4328 | efiring | 2007-11-16 02:47:51 -0500 (Fri, 16 Nov 2007) | 2 lines ScalarMappable.to_rgba can return uint8 instead of float64 ........ r4329 | dsdale | 2007-11-16 08:16:12 -0500 (Fri, 16 Nov 2007) | 2 lines removed numpy.seterr(invalid='ignore') from axes.py ........ svn path=/branches/transforms/; revision=4330
1 parent ec7da01 commit 52ae800

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

lib/matplotlib/axes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2597,7 +2597,6 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
25972597

25982598
self._process_unit_info(xdata=x, ydata=ymin, kwargs=kwargs)
25992599

2600-
26012600
if not iterable(x): x = [x]
26022601
if not iterable(ymin): ymin = [ymin]
26032602
if not iterable(ymax): ymax = [ymax]

lib/matplotlib/cm.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ def set_colorbar(self, im, ax):
4545
'set the colorbar image and axes associated with mappable'
4646
self.colorbar = im, ax
4747

48-
def to_rgba(self, x, alpha=1.0):
48+
def to_rgba(self, x, alpha=1.0, bytes=False):
4949
'''Return a normalized rgba array corresponding to x.
5050
If x is already an rgb or rgba array, return it unchanged.
5151
'''
52-
if hasattr(x, 'shape') and len(x.shape)>2: return x
52+
try:
53+
if x.ndim == 3 and (x.shape[2] == 3 or x.shape[2] == 4):
54+
return x
55+
except AttributeError:
56+
pass
5357
x = ma.asarray(x)
5458
x = self.norm(x)
55-
x = self.cmap(x, alpha)
59+
x = self.cmap(x, alpha=alpha, bytes=bytes)
5660
return x
5761

5862
def set_array(self, A):

lib/matplotlib/colors.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def __init__(self, name, N=256):
407407
self._isinit = False
408408

409409

410-
def __call__(self, X, alpha=1.0):
410+
def __call__(self, X, alpha=1.0, bytes=False):
411411
"""
412412
X is either a scalar or an array (of any dimension).
413413
If scalar, a tuple of rgba values is returned, otherwise
@@ -416,6 +416,8 @@ def __call__(self, X, alpha=1.0):
416416
If they are floating point, then they must be in the
417417
interval (0.0, 1.0).
418418
Alpha must be a scalar.
419+
If bytes is False, the rgba values will be floats on a
420+
0-1 scale; if True, they will be uint8, 0-255.
419421
"""
420422

421423
if not self._isinit: self._init()
@@ -440,7 +442,11 @@ def __call__(self, X, alpha=1.0):
440442
npy.putmask(xa, xa<0, self._i_under)
441443
if mask_bad is not None and mask_bad.shape == xa.shape:
442444
npy.putmask(xa, mask_bad, self._i_bad)
443-
rgba = self._lut[xa]
445+
if bytes:
446+
lut = (self._lut * 255).astype(npy.uint8)
447+
else:
448+
lut = self._lut
449+
rgba = lut[xa]
444450
if vtype == 'scalar':
445451
rgba = tuple(rgba[0,:])
446452
return rgba

0 commit comments

Comments
 (0)