Re: question about coloring lines in x-y plot

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon May 23 2011 - 07:56:10 MDT

On May 20, 2011, at 7:19 PM, Erik Noble wrote:

> Hi, is there a way to use the range of a color table to color all lines drawn in an x-y plot, instead of having to name each color or color-index?
> Is there an example of this? Maybe I missed it.
> I have 32 line, as shown in my plots.

Hi Erik,

If you're looking for something like gsnSpreadColors for XY plots, there isn't anything. The only way to color multiple lines in an XY plot is via the xyLineColors resource.

You could retrieve the number of colors in your color map, get the number of lines you have, and then use this information to calculate a "step" index through your color map.

To retrieve the size of your color map:

wks = gsn_open_wks("ps","example")
. ..
getvalues wks
  "wkColorMapLen" cmaplen
end getvalues

You can then use "numFiles" and "cmaplen" to figure out a nice spacing, and use ispan to generate the range of colors for xyLineColors.

--Mary

>
> My code is below.
> Thank you in advance.
>
>
> 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
> ;***** TRMM precipitation ********
> filO = "hov_ncpr2_rv.nc"
> dirM = "./"
> filM = "hov_regridded_rv_700_Experiment_*"
>
> ;***** OBSERVED precipitation ********
> obs = addfile(filO,"r")
> obsv = obs->rv ;rain
> rain_obs = obsv
>
> all_files = systemfunc ("ls "+dirM+filM)
> ;print(all_files)
> numFILES = dimsizes(all_files)
> f = addfiles (all_files+".nc", "r")
> ListSetType (f, "join")
> r = f[:]->rv
> rain_model = r(:,1::,:)
> dimp = dimsizes(rain_model)
>
> ; check data
> printVarSummary(rain_obs)
> printVarSummary(rain_model)
>
> ;;;;;; MAKE ARRAY FOR CC ;;;;;;;;;;;;;;;
> ARRAY = new ( (/numFILES,12/), float,-9999)
> ARRAY2 = new ( (/numFILES,12/), float,-9999)
> ;******************************
> ; Generate Correlation Coefficient
> ;******************************
> do i = 0, 31, 1
> do j=0,11,1
> ARRAY(i,j) = escorc(ndtooned(rain_model(i,0:j,:)),ndtooned(rain_obs(0:j,:)))
> ARRAY2(i,j)= escorc(ndtooned(rain_model(i,j:11,:)),ndtooned(rain_obs(j:11,:)))
> end do
> end do
>
> printVarSummary(ARRAY)
> printMinMax(ARRAY,True)
> printVarSummary(ARRAY2)
> printMinMax(ARRAY2,True)
>
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Make Plot
> wks = gsn_open_wks("ps","xy")
> x=ispan(1,12,1)
> res = True
> res@trYMaxF = 0.70
> res@trYMinF = -0.70
> ;res@tiMainString = "Title"
> res@tiYAxisString = "Correlation Coefficient"
> res@tiXAxisString = "Days"
> ; res@xyLineColors = (/ /)
> ; res@xyLineThicknesses = (/ /) ; line thicknesses
> ; res@xyDashPatterns = (/ /) ; line patterns
> ; res@xyDashPattern = 1 ; Make curves all solid
> res@xyMarkLineMode = "MarkLines" ; Markers *and* lines
> res@trXMinF = 1
>
> res@tmXBLabels = ispan(1,12, 1)
> res@tmLabelAutoStride = True
> plot = gsn_csm_xy(wks,x,ARRAY,res)
>
> plot = gsn_csm_xy(wks,x,ARRAY2,res)
> end
> <xy.ps>_______________________________________________
> 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 May 23 07:56:21 2011

This archive was generated by hypermail 2.1.8 : Wed May 25 2011 - 09:35:33 MDT