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?
If you mean using the keyword ‘alpha’ in the pcolormesh function, then yes, that isn’t the right place for it. In your case, the right place to specify the alpha channel is in the colormap itself. Unfortunately, it is currently designed around the idea of a scalar value specifying the transparency.
What you can do is a little trick. First, get the colormap object and then initialize it. This will cause it to internally create an array called “_lut” which holds rgba values.
theCM = cm.get_cmap(‘somemap’)
Then, you need to fill in the alpha values for yourself. For this, I am going to use a triangle function:
alphas = np.abs(np.linspace(-1.0, 1.0, theCM.N))
theCM._lut[:,-1] = alphas
Now that your colormap is set up, you can pass it into your pcolormesh call.
plt.pcolormesh(X, Y, C, cmap=theCM)
That should work, but I have not fully tested it. I hope that helps!
On Tue, Oct 12, 2010 at 7:57 AM, Stefan Mauerberger <stefan.mauerberger@…3317…> wrote: