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

Kyle Griffin ksgriffin2 at wisc.edu
Thu Aug 28 20:42:47 MDT 2014


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140828/18836d74/attachment.html 


More information about the ncl-talk mailing list