On Fri, Jun 5, 2009 at 9:56 PM, Fernando Perez<[email protected]> wrote:
> Hopefully the code below is illustrative and commented enough to
> clarify my question (also attached if you prefer to download it than
> to copy/paste).
Hey Fernando -- thanks for the report and test case.
I committed a change to svn which fixes this -- I'd like one of the
color gurus (Eric?) to take a look at this because the color handling
code is fairly complex as it handles a lot of different cases. The
problem here was that the ColorConverter.to_rgba_array was applying
the alpha even though the input array was rgba already. I special
case this and do not convert when the input is already an Nx4 array.
Are there any cases I am missing? See the inline comment below:
def to_rgba_array(self, c, alpha=None):
"""
Returns a numpy array of *RGBA* tuples.
Accepts a single mpl color spec or a sequence of specs.
Special case to handle "no color": if *c* is "none" (case-insensitive),
then an empty array will be returned. Same for an empty list.
"""
try:
if c.lower() == 'none':
return np.zeros((0,4), dtype=np.float_)
except AttributeError:
pass
if len(c) == 0:
return np.zeros((0,4), dtype=np.float_)
try:
result = np.array([self.to_rgba(c, alpha)], dtype=np.float_)
except ValueError:
if isinstance(c, np.ndarray):
if c.ndim != 2 and c.dtype.kind not in 'SU':
raise ValueError("Color array must be two-dimensional")
if len(c.shape)==2 and c.shape[-1]==4:
# looks like rgba already, nothing to be done; do
# we want to apply alpha here if
# (c[:,3]==1).all() ?
return c
result = np.zeros((len(c), 4))
for i, cc in enumerate(c):
result[i] = self.to_rgba(cc, alpha) # change in place
return np.asarray(result, np.float_)
JDH
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel