Re: reversing a color palette

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Oct 28 2013 - 11:24:19 MDT

Hi Solange,

To reverse a color map and use it with cnFillPalette, I recommend
first using the read_colormap_file to read the color map in as an RGBA
array, reverse it, and then assign it to cnFillPalette.

I'm not sure which colormap you wanted to reverse, so I'll use the spread_15lev
one as an example:

cmap = read_colormap_file("spread_15lev")
cmap = cmap(::-1,:) ; reverse the color map
. . .
res@cnFillPalette = cmap

Note that you can reassign a reversed array back to the original variable, as long as the dimension sizes don't change.

--Mary

On Oct 26, 2013, at 8:43 AM, Solange.Fermepin@lmd.jussieu.fr wrote:

> Hello everybody,
>
> I'm trying to make a panel plot with two different color tables, one of
> which I actually need reversed.
>
> I would like to use the cnFillPalette resource, since it is easier to
> manage individually for each figure of the panel (below, the relevant part
> of my code). However, I did not find a way to reverse the palette...
>
> All I found were gsn resources to reverse a colormap of a wks, and if I
> use them (I tried just in case) it gives me an error
> (warning:ContourPlotSetValues: color index (209) exceeds size of palette,
> defaulting to foreground color for entry (9)).
> I can not merge the color maps since I think that wether I reverse both
> palettes or none.
>
> I guess I can try to make my own palette by retrieving the colors of ecah
> palette, and manually reverse the ones I need. I was wondering whether
> there is an easy solution for my problem that I'm missing.
>
> Thanks a lot!
> Solange
>
>
> plot1 = new(6,graphic)
> res@cnFillPalette = "precip4_11lev"
> res@cnSpanFillPalette = True
> res@cnLevelSelectionMode = "ManualLevels" ; set manual contour
> levels
> res@cnMinLevelValF = -80. ; set min contour level
> res@cnMaxLevelValF = 0.
> res@cnLevelSpacingF = 8.
> plot1(0) = gsn_csm_contour_map_ce(wks,swtoa_obs,res)
> plot1(1) = gsn_csm_contour_map_ce(wks,swsfc_obs,res)
> res@cnFillPalette = "spread_15lev"
> delete(res@cnLevelSelectionMode)
> res@cnLevelSelectionMode = "ExplicitLevels"
> res@cnLevels = (/ 0.,5.,10.,15.,20.,25.,30.,40.,50.,60.,70./)
> res@lbLabelStride = 1.
> plot1(2) = gsn_csm_contour_map_ce(wks,lwtoa_obs,res)
>
>
> --
> Solange Fermepin, PhD student
> Laboratoire de Météorologie Dynamique - CNRS/IPSL
> Tour 45-55, 3ème étage
> 4 place Jussieu
> 75252 Paris cedex 05
> France
>
> Tel: +33 (0) 1 44 27 52 55
> E-mail: solange.fermepin@lmd.jussieu.fr
> _______________________________________________
> 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 Mon Oct 28 11:24:30 2013

This archive was generated by hypermail 2.1.8 : Fri Nov 01 2013 - 08:58:14 MDT