Re: Color map manipulation

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Feb 23 2012 - 08:06:57 MST

Hi Freddie,

You can programmatically change the color in a color map by using gsn_retrieve_colormap as Adam pointed out,
looping through to find the white color, and using NhlSetColor to replace it with gray. See the attached script.

If you are going to use the color map a lot, then you can make a copy of $NCARG_ROOT/lib/ncarg/colormaps/precip_diff_12lev.rgb
(maybe call it $NCARG_ROOT/lib/ncarg/colormaps/precip_diff_12lev_gray.rgb) and simply replace the line:

 255 255 255

with your choice of gray, say:

127 127 127

You can then use "precip_diff_12lev_gray" as an official color map name.

If you don't have permissions to write to the $NCARG_ROOT/lib/ncarg/colormaps directory, then see:

http://www.ncl.ucar.edu/Document/Graphics/create_color_table.shtml#MoveColorTableFile

for information on using a local directory.

--Mary

On Feb 22, 2012, at 4:23 PM, Adam Phillips wrote:

> Hi Freddie,
> To add white to your printed labelbar you have two choices:
> 1) As white is already part of the colormap (color indices 0 and 8), it is probably easiest to specify exactly which colors correspond to which contour intervals.
>
> You can do this by setting cnFillColors (and not setting gsnSpreadColors = True if you were doing so), using the indices shown here:
> www.ncl.ucar.edu/Document/Graphics/ColorTables/precip_diff_12lev.shtml
>
> res@cnLevelSelectionMode = "ExplicitLevels"
> res@cnLevels = (/-.3,-.2,-.1,0,0.1,0.2/)
> res@cnFillColors = (/2,4,6,8,8,10,12,14/) ; #s refer to indices
>
> If you wish to change the white to gray, you first have to add gray to your colormap. The easiest way to do this is to use NhlNewColor after you open the workstation:
> wks = gsn_open_wks("ps",get_script_prefix_name())
> gsn_define_colormap(wks,"precip_diff_12lev")
> nc1 = NhlNewColor(wks,0.5,0.5,0.5) ; = medium gray
> nc2 = NhlNewColor(wks,0.8,0.8,0.8) ; = light gray
>
> Note that in the above medium gray would be added to precip_diff_12lev as the 15th color index, and light gray would be added as the 16th color index.
> To use the light gray in the middle set
> res@cnFillColors = (/2,4,6,16,16,10,12,14/)
>
> 2) You can manipulate the loaded color table yourself. I won't go into details here as option #1 is much easier. But see:
> http://www.ncl.ucar.edu/Applications/color.shtml#ex16
>
> example 16 shows how to load a colormap, retrieve it, and modify it.
>
> Hope that helps. If not, let ncl-talk know.
> Good luck,
> Adam
>
>
> On 02/22/2012 03:51 PM, Freddie.Mpelasoka@csiro.au wrote:
>> Dear ncl experts,
>>
>> I am learning to produce plots using ncl. How can I manipulate "precip_diff_12lev "color map to have white color around zero (i.e. over [-0.1 and +0.1]) for the range /-0.3, -0.2, -0.1, 0., 0.1,0.2/. I am also wondering if the "white" color in the "precip_diff_12lev "can be replaced with "grey". Your help will be highly appreciated.
>>
>>
>> Many thanks,
>>
>> Freddie
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>>
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> --
> ______________________________________________________________
> Adam Phillips
> asphilli@ucar.edu
>
> NCAR/Climate and Global Dynamics Division (303) 497-1726
> P.O. Box 3000
> Boulder, CO 80307-3000
> http://www.cgd.ucar.edu/cas/asphilli
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Thu Feb 23 08:07:11 2012

This archive was generated by hypermail 2.1.8 : Thu Feb 23 2012 - 10:01:53 MST