Variable alpha blending in pylab

Posted by Hooked on Stack Overflow See other posts from Stack Overflow or by Hooked
Published on 2010-03-22T20:52:46Z Indexed on 2010/03/22 21:31 UTC
Read the original article Hit count: 338

Filed under:
|
|
|

How does one control the transparency over a 2D image in pylab? I'd like to give two sets of values (X,Y,Z,T) where X,Y are arrays of positions, Z is the color value, and T is the transparency to a function like imshow but it seems that the function only takes alpha as a scalar. As a concrete example, consider the code below that attempts to display two Gaussians. The closer the value is to zero, the more transparent I'd like the plot to be.

from pylab import *

side = linspace(-1,1,100)
X,Y  = meshgrid(side,side)

extent = (-1,1,-1,1)

Z1  = exp(-((X+.5)**2+Y**2))
Z2  = exp(-((X-.5)**2+(Y+.2)**2))

imshow(Z1, cmap=cm.hsv, alpha=.6, extent=extent)
imshow(Z2, cmap=cm.hsv, alpha=.6, extent=extent)
show()

Note: I am not looking for a plot of Z1+Z2 (that would be trivial) but for a general way to specify the alpha blending across an image.

© Stack Overflow or respective owner

Related posts about python

Related posts about matplotlib