[ncl-talk] Can i set the opacity of each color ??

Kyle Griffin ksgriffin2 at wisc.edu
Thu Aug 28 21:32:16 MDT 2014


Hi Rabah,

As far as I know, gsn_define_colormap does not support RGBA colors, but I
can't immediately find that in the documentation. If you want to use all of
the colors in your color array, directly assign res at cnFillColors = colors
(or colors(:,0:2) if you only want the first three colors) and this will
set all of the colors in that array to be used in the FillColors. However,
I believe the "more proper" way is to use cnFillPalette, as specified in
the link I sent you in the last email.


Kyle

----------------------------------------
Kyle S. Griffin
Department of Atmospheric and Oceanic Sciences
University of Wisconsin - Madison
Room 1421
1225 W Dayton St, Madison, WI 53706
Email: ksgriffin2 at wisc.edu


On Thu, Aug 28, 2014 at 10:17 PM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
wrote:

> Hi Kyle,
>
> I think your suggestion doesn't work because when i add the 4th values for
> opacity i get this message ;
> (0)     Warning: gsn_define_colormap: cmap must either be an n x 3 float
> array,
> (0)     a single pre-defined colormap name, or a 1-dimensional string
> array of named colors.
>
> i simplified my script like this :
>
> colors = (/ (/255,255,255,1/), (/163,255,163,125/), (/255,178,102,200/) /)
> * 1.0
> colors= colors/255.
> print(colors)
>
> gsn_define_colormap(wks,colors)
> ......
> ......
> .........
> res at cnLevelSelectionMode = "ExplicitLevels"     ; set explicit contour
> levels
> res at cnLevels    = (/ 40,70,100/) ; set levels
> res at cnFillColors = (/ 0,1,2/)
>
>
>
>
>
> 2014-08-28 22:42 GMT-04:00 Kyle Griffin <ksgriffin2 at wisc.edu>:
>
> You should be able to just add a fourth value to your RGB triplets to make
>> them RGBA (A for alpha) quadruplets. Since you already divide the numbers
>> out of 255, you can simply add the alpha on the same scale, with 0 =
>> transparent and 1=opaque (or 255, in your case).
>>
>> More of the problem is that you don't seem to be assigning the color
>> array you create at the beginning of the script to the cnFillColors
>> resource you set later on. Look at some of the examples on the NCL website
>> discussing how to work with the new color capabilities at:
>> http://www.ncl.ucar.edu/Applications/rgbacolor.shtml
>>
>>
>> Kyle
>>
>> ----------------------------------------
>> Kyle S. Griffin
>> Department of Atmospheric and Oceanic Sciences
>> University of Wisconsin - Madison
>> Room 1421
>> 1225 W Dayton St, Madison, WI 53706
>> Email: ksgriffin2 at wisc.edu
>>
>>
>> On Thu, Aug 28, 2014 at 8:44 PM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
>> wrote:
>>
>>>
>>> Hi all ,
>>>
>>> I am using the script below to plot humidity between 40-70%(green) and
>>> 70-100% (orange).
>>>
>>> I want to know if i can set the opacity for each color for example
>>> opacity 50% for the green color and 100% for the orange.
>>>
>>> Thanks for help.
>>>
>>> ;************************************************
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>> ;************************************************
>>> begin
>>>  a = addfile("gfs.t00z.pgrb2f00.grib2","r")
>>>     lon = a->lon_0
>>>     lat = a->lat_0
>>>     icing     = short2flt(a->RH_P0_L100_GLL0({50000},:,:))
>>>
>>> print(icing(1:4,1:4))
>>> ;********************************************************
>>> ;  Display parameters
>>> ;***************************************
>>> zoom="test"
>>> pixel=2048
>>> ;***************************************************
>>>
>>> wks_type="png"
>>>
>>>   wks_type at wkWidth = pixel
>>>    wks_type at wkHeight = pixel
>>>   wks_type at wkBackgroundOpacityF = 0.0
>>> wks = gsn_open_wks(wks_type,"icing_test")
>>>
>>> colors = (/ (/255,255,255/),(/0,0,0/),(/255,255,255/), (/244,255,244/), \
>>>               (/217,255,217/), (/163,255,163/), (/106,255,106/), \
>>>               (/43,255,106/), (/0,224,0/), (/0,134,0/),(/255,145,0/),\
>>>               (/255,178,102/) /) * 1.0 ; we multiply by 1 to make colors
>>> float
>>>
>>> colors = colors/255.
>>>
>>>
>>> gsn_define_colormap(wks,colors)
>>>
>>>
>>> res                   = True
>>>   res at mpProjection      = "Mercator"       ; choose projection
>>>   res at mpGridAndLimbOn   = False             ; turn on lat/lon lines
>>>   res at mpPerimOn         = False             ; turn off box around plot
>>>   res at mpFillOn          = False
>>>   res at mpOutlineOn       = True
>>>   res at cnFillOn          = True              ; color plot desired
>>>   res at cnLineLabelsOn    = False             ; turn off contour lines
>>>    res at mpLimitMode  = "LatLon"
>>>    res at mpMinLatF            =   -85.0
>>>     res at mpMaxLatF            =  85.0
>>>     res at mpMinLonF            = -180
>>>     res at mpMaxLonF            = 180
>>>   res at vpXF            = 0                 ; make plot bigger
>>>   res at vpYF            = 1
>>>   res at vpWidthF        = 1
>>>   res at vpHeightF       = 1
>>>
>>> res at cnLevelSelectionMode = "ExplicitLevels"    ; set explicit contour
>>> levels
>>> res at cnLevels    = (/ 40,70,100/) ; set levels
>>> res at cnFillColors = (/ -1,5,11/)
>>>
>>> ;res at cnFillOpacityF=0.5
>>>
>>> contour0 = gsn_csm_contour_map(wks,icing,res)  ; create the plot
>>> --
>>> ------------------------------
>>> Cordialement,
>>> Best regards,
>>> Rabah Hachelaf
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> ------------------------------
>>> Cordialement,
>>> Best regards,
>>> Rabah Hachelaf
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
>
> --
> ------------------------------
> Cordialement,
> Best regards,
> Rabah Hachelaf
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140828/431d1afe/attachment.html 


More information about the ncl-talk mailing list