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

Mary Haley haley at ucar.edu
Mon Sep 1 22:16:52 MDT 2014


Hi Kyle,

I've added a ticket, NCL-2058, for a "cnFillOpacities" type of resource. I
don't think this would be an issue.

--Mary



On Fri, Aug 29, 2014 at 4:20 PM, Kyle Griffin <ksgriffin2 at wisc.edu> wrote:

> Hi Mary,
>
> Thanks for the clarification. I think Rabah would need to use
> cnFillPalette as it seems like he has multiple opacities to set that vary
> by color. On a related note, is it possible to readily change
> cnFillOpacityF to accept an array of values, much like setting cnFillColors
> allows one to set RGB/RGBA colors? This would allow for a more readily
> accessible method of setting varying opacities rather than via direct
> manipulation of the color quadruplets. Just a suggestion, as I've generally
> struggled in my attempts to make alpha values work from a color table file.
>
>
> 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 Fri, Aug 29, 2014 at 4:22 PM, Mary Haley <haley at ucar.edu> wrote:
>
>> Hi Kyle and Rabah,
>>
>> Sorry about the confusion on gsn_define_colormap.  It doesn't seem to
>> handle RGBA type color maps, although you can certainly set a colormap
>> using gsn_define_colormap, and then apply opacity to it later via opacity
>> resources like cnFillOpacityF
>>
>> We recommend using "cnFillPalette" if you want to use a color map that
>> has various opacity values set.
>>
>> See the attached example, which you should be able to run as-is.  It
>> shows two ways to set opacities.
>>
>> I'm not sure what's going on with the labelbar, and whether this is
>> correct. Rick will need to weigh in here.
>>
>> --Mary
>>
>>
>>
>> On Thu, Aug 28, 2014 at 9:32 PM, Kyle Griffin <ksgriffin2 at wisc.edu>
>> wrote:
>>
>>> 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
>>>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140901/09b00738/attachment.html 


More information about the ncl-talk mailing list