David Goldsmith wrote:
> Hi, folks.  OK, I'm trying to set the alpha channel, pixel by pixel, using 
> figimage w/ the data being of the "luminance" type (i.e., an MxN array).  The 
> Users Guide indicates that figimage takes an alpha= keyword argument, and it 
> doesn't crash when I pass an array for this value, but subsequently when I 
> try to draw it using fig.draw(canvas.get_renderer()), I get:
>
>   
>>>> fig.draw(canvas.get_renderer())
>>>>         
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "C:\python25\lib\site-packages\matplotlib\figure.py", line 607, in draw
>     im.draw(renderer)
>   File "C:\python25\lib\site-packages\matplotlib\image.py", line 597, in draw
>     im = self.make_image()
>   File "C:\python25\lib\site-packages\matplotlib\image.py", line 583, in 
> make_im
> age
>     x = self.to_rgba(self._A, self._alpha)
>   File "C:\python25\lib\site-packages\matplotlib\cm.py", line 76, in to_rgba
>     x = self.cmap(x, alpha=alpha, bytes=bytes)
>   File "C:\python25\lib\site-packages\matplotlib\colors.py", line 423, in 
> __call
> __
>     alpha = min(alpha, 1.0) # alpha must be between 0 and 1
> ValueError: The truth value of an array with more than one element is 
> ambiguous.
>  Use a.any() or a.all()
>
> which to me "smells" as if the array-valued alpha is the problem.  
>
> Clearly (?) I can do what I'm after if I use MxNx4 data, but is that the only 
> way to have a varying alpha?
>   
The alpha parameter always takes only a single (global) value, and the 
only way to do pixel-by-pixel alpha is an MxNx4 array.  It should be 
fairly straightforward to create this array by concatenating together 
three copies of the luminance and one copy of your alpha, though.

Something like:

  # lum is MxN, alpha is MxN
  lum = lum.reshape((M, N, 1))
  alpha = alpha.reshape((M, N, 1))
  rgba = numpy.concatenate((lum, lum, lum, alpha))

(There might be an even more straightforward way --- I'm not much of a 
numpy expert...)

Cheers
Mike

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to