On Tue, Oct 12, 2010 at 9:25 AM, Benjamin Root <ben.r...@ou.edu> wrote:
> On Tue, Oct 12, 2010 at 7:57 AM, Stefan Mauerberger <
> stefan.mauerber...@mnet-online.de> wrote:
>
>> Hi everyone,
>>
>> 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?
>>
>> Regards
>>
>> Stefan
>>
>>
> Stefan,
>
> 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')
> >>> theCM._init()
>
> 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!
> Ben Root
>
>
Slight correction to my code example:
>>> theCM._lut[:-3,-1] = alphas
Sorry for any confusion.
Ben Root
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users