|
From: Scott S. <sco...@gm...> - 2010-10-12 14:27:58
|
On 12 October 2010 14:57, Stefan Mauerberger <ste...@mn...> wrote: > I am having trouble with colormaps unsing pcolormesh. I would like to > plot and colorise a seismic wave field above a map. Plotting works fine > but I do not know how to bring transparency into colormaps. For negative > values I want the coloration being blue then it should become > transparent and the greatest value should be drawn red. I have tried a > lot but without any success. As far as I can see, the keyarg alpha does > not fit my needs at all. > > Do you have any suggestions for me? You can't make the actual colormap contain transparent color entries, but you can easily plot a masked array using a custom colormap. The attached script based on http://matplotlib.sourceforge.net/examples/pylab_examples/custom_cmap.html should help you get what you want. The important part of the script is to create a Numpy masked array to exclude the regions you'd like to appear transparent: cond = (-0.1 < Z) & (Z < 0.1) Z_masked = np.ma.masked_where(cond, Z) Cheers, Scott |