Custom CMAP

655 views
Skip to first unread message

dmc...@uah.edu

unread,
Nov 16, 2016, 5:29:21 PM11/16/16
to Py-ART Users
Hi all,

I am trying to create a custom cmap to use with the plot_grid function and I am having some trouble trying to get it to work.

I have this so far:

colors=[
(0,0,0),
(.8627,.8627, .8627),
(.5569,.4745,.7098),
(.0392,.0392, .6078),
(.2667,.9725,.8314),
(.3529,.8667,.3843),
(1,1,.3922),
(.8627,.0392,.0196),
(.6863,0,0),
(.9412, .4706,.7059),
(1,1,1),
    (.5686,.1765,.5882)  
    ]
 

 
zdr = mpl.colors.LinearSegmentedColormap.from_list('zdr',colors,12)
 
vmax = 8.0
zdr = mpl.colors.LinearSegmentedColormap.from_list('mycmap', [(-4 / vmax, (0,0,0)), (0 / vmax, (.8627,.8627, .8627)), (0 / vmax, (.5569,.4745,.7098)), (.25 / vmax, (.0392,.0392, .6078)), 
                                                   (1 / vmax, (.2667,.9725,.8314)), (1.5 / vmax, (.3529,.8667,.3843)), (2 / vmax, (1,1,.3922)), (3 / vmax, (.8627,.0392,.0196)), 
                                                   (4 / vmax, (.6863,0,0)), (5 / vmax, (.9412, .4706,.7059)), (6 / vmax, (1,1,1)), (8 / vmax, (.5686,.1765,.5882))])




But I keep getting the follow error:

ValueError: data mapping points must start with x=0. and end with x=1



I tried to follow something along the lines of this post (http://stackoverflow.com/questions/24997926/making-a-custom-colormap-using-matplotlib-in-python) but with no luck.


Any help or suggestions on an easier way to do this would be extremely helpful. Thank you!


Dustin


Jonathan Helmus

unread,
Nov 21, 2016, 1:21:33 PM11/21/16
to pyart...@googlegroups.com
Dustin,

    Defining your own colormaps with matplotlib can be tricky.  I believe you need to explicitly set the vmin and vmax parameters when you use a colormap which does not start and end from 0 and 1.  The following lines of code allow me to plot the differential reflectivity of some test data using the colormap defined in the snippet you shared:

radar = pyart.io.read('./KATX20130717_195021_V06')
display = pyart.graph.RadarDisplay(radar)
display.plot_ppi(
    'differential_reflectivity', cmap=zdr, vmin=-4/vmax, vmax=vmax)

Defining vmin and vmax in the plot_ppi method call seems to be the key to using the custom cmap.  It should be possible to defining the scaling using the norm argument if you want non-linear scaling.

Cheers,

    - Jonathan Helmus
--
You received this message because you are subscribed to the Google Groups "Py-ART Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyart-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages