This Page

Quick search

"""Layer images above one another using alpha blending"""from__future__importdivisionimportmatplotlib.pyplotaspltimportnumpyasnpdeffunc3(x,y):return(1-x/2+x**5+y**3)*np.exp(-(x**2+y**2))# make these smaller to increase the resolutiondx,dy=0.05,0.05x=np.arange(-3.0,3.0,dx)y=np.arange(-3.0,3.0,dy)X,Y=np.meshgrid(x,y)# when layering multiple images, the images need to have the same# extent. This does not mean they need to have the same shape, but# they both need to render to the same coordinate system determined by# xmin, xmax, ymin, ymax. Note if you use different interpolations# for the images their apparent extent could be different due to# interpolation edge effectsxmin,xmax,ymin,ymax=np.amin(x),np.amax(x),np.amin(y),np.amax(y)extent=xmin,xmax,ymin,ymaxfig=plt.figure(frameon=False)Z1=np.array(([0,1]*4+[1,0]*4)*4)Z1.shape=(8,8)# chessboardim1=plt.imshow(Z1,cmap=plt.cm.gray,interpolation='nearest',extent=extent)Z2=func3(X,Y)im2=plt.imshow(Z2,cmap=plt.cm.viridis,alpha=.9,interpolation='bilinear',extent=extent)plt.show()