Re: Polylines in each panel plot

From: Jonathan Vigh <jvigh_at_nyahnyahspammersnyahnyah>
Date: Wed Dec 22 2010 - 10:32:08 MST

Ibo,
     You need to call gsn_panel *after* you have added the polylines to
each plot. Also, since you have 6 plots, you need to have 7 data values
in your xpts and ypts arrays (the extra one is the cyclic point). I
added a couple dummy values below to make it work. Also, the array 'dum'
needs to be the same size as your number of plots. Finally, it isn't
necessary to call draw(plot) and frame(wks) at the end because gsn_panel
does this for you.

Just FYI, if you were going to add multiple polylines on each plot (not
just one like you are here), then dum would need to be as large as the
total number of line segments to be drawn because each poly-primitive
needs to have it's own unique identifier in NCL (at least as far as I
know). If you are drawing many types of polylines, then for a panel
plot, it'd be easier to write a wrapper function which generates a
unique id for each line segment. Mary helped me with a solution like
this last year - I've included it below.

Hope this helps!
Jonathan

<<< new code snippet
  ypts = (/ 34, 34, 29.5, 29.5, 34, 25, 45/)
  xpts = (/ 69.3, 74.5, 74.5, 69.3, 69.3, 75, 80/)

  resb = True ; polyline mods
desired
  resb@gsLineColor = "black" ; color of lines
  resb@gsLineThicknessF = 1.0 ; thickness of
lines

  dum = new(6,graphic)

    do j = 0,5
     dum(j)=gsn_add_polyline(wks,plots(j),xpts(j:j+1),ypts(j:j+1),resb)
    end do

  pres = True
  pres@gsnFrame = True
  pres@gsnPanelLabelBar = True
  pres@pmLabelBarWidthF = 0.8

  gsn_panel(wks,plots,(/3,2/),pres)

; draw(plots)
; frame(wks)

Here's that wrapper:

;********************************************************
; procedure add_line
;
; This procedure adds a line to a plot, making sure that each
; set is returned to a unique variable name, and that this
; variable is retained even outside this procedure call.
;********************************************************
undef("add_line");
procedure
add_line(wks[1]:graphic,plot[1]:graphic,x[2]:numeric,y[2]:numeric,color[1]:string,thickness[1]:float,dash_pattern[1]:integer,dash_segment_length[1]:numeric)

local plres,polyline

begin

   plres = True

   plres@gsLineColor = color
   plres@gsLineThicknessF = thickness
   plres@gsLineDashPattern = dash_pattern
   plres@gsLineDashSegLenF = dash_segment_length

   polyline = unique_string("polyline") ; "unique_string" will return
a unique
                                          ; string every time it is
called from
                                          ; within a single NCL session.

; You can then use this unique string as an attribute variable name
; that gets attached to the plot variable. This ensures that this
; value will live for the duration of the script.

   plot@$polyline$ = gsn_add_polyline(wks,plot,x,y,plres)

end

Usage in your main script would be like:

;********************************************************
; draw reference line at t = 0
;********************************************************
   plres = True

   plres@gsLineColor = "black"
   plres@gsLineThicknessF = 2.0
   plres@gsLineDashPattern = 0
   plres@gsLineDashSegLenF = 0

   xpts = (/0,0/)
   ypts = (/res@trYMinF,res@trYMaxF/)
   Jgsn_add_polyline(wks,plot,xpts,ypts,plres)

If you were doing multiple line segments, you'd just keep changing xpts
and ypts and repeatedly calling Jgsn_add_polyline.

On 12/22/2010 10:04 AM, Ibo Ze wrote:
> Thanks Rick. But now i am getting two pages: one without box and
> second page with only one map [with box] instead of six panel plots.
> Is there any workaround/thoughts how to fix it?
>
> thanks
> ------------------------------------------------------------------------
> *From:* Rick Brownrigg <brownrig@ucar.edu>
> *To:* Ibo Ze <ibo85@ymail.com>
> *Cc:* Ncl Talk <ncl-talk@ucar.edu>
> *Sent:* Wed, December 22, 2010 10:25:58 AM
> *Subject:* Re: [ncl-talk] Polylines in each panel plot
>
> Hi,
>
> I *think* the issue is that you need to draw the polylines explicitly
> on each plot. In:
>
>> do j = 0,3
>> dum(j)=gsn_add_polyline(wks,plots,xpts(j:j+1),ypts(j:j+1),resb)
>> end do
>
> "plots" is an array of size 6. I think you want to loop over plots,
> not points:
>
> dum = new(6, graphic)
> do j=0,5
> dum(j) = gsn_add_polyline(wks, plots(j), xpts, ypts, resb)
> end do
>
> Hope that helps.
> Rick
>
> On Dec 22, 2010, at 4:21 AM, Ibo Ze wrote:
>
>> Hi All,
>>
>> I've been trying to plot polylines to be overlayed at each panel plot
>> in a frame.
>> But the polylines part of script gives gives following error:
>>
>> fatal:Number of elements of dimension (0) of argument (0) is (6) in
>> function (NhlAddPrimitive), expected (1) elements
>> fatal:Execute: Error occurred at or near line 3632 in file
>> $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl
>>
>> fatal:Execute: Error occurred at or near line 3897 in file
>> $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl
>>
>>
>> Below is my script. I would appreciate if someone can help me to
>> resolve this issue.
>>
>> thanks,
>> Ibo
>>
>> 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"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>>
>> begin
>>
>> wks = gsn_open_wks("pdf","pkc") ; ps or x11 to
>> save or visualize
>> gsn_define_colormap(wks,"BlueDarkRed18")
>>
>> res = True ;
>> No plot options set.
>> res@gsnDraw = False
>> res@gsnFrame = False
>> res@cnFillOn
>> = True
>> res@cnInfoLabelOn = False
>> res@gsnMaximize = True
>> res@cnLevelSelectionMode = "ExplicitLevels" ;
>> manually set cn levels
>> res@cnMinLevelValF = -1 ;
>> min level
>> res@cnMaxLevelValF = 1 ;
>> max level
>> res@cnLevels =
>> (/"-1.0","-0.9","-0.8","-0.7","-0.6","-0.5","-0.4","-0.3","-0.2",\
>>
>> "0.0","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0"/)
>> res@cnLinesOn = False ;
>> Turn off contour lines
>> res@gsnSpreadColors = True
>> res@gsnAddCyclic = False
>> res@lbLabelBarOn = False
>>
>> plots = new(6,graphic)
>> do i=0,5
>> j = i+5
>> filename1 = "pkc."+sprinti("%0.2i",j)+".7906.wa.nc
>> <http://7906.wa.nc>"
>> f1 = addfile(filename1,"r")
>> x1 = f1->pre
>> ;print(x1)
>> ;printVarSummary(x1)
>> filename2 = "medd."+sprinti("%0.2i",j)+".7906.nc <http://7906.nc>"
>> f2 = addfile(filename2,"r")
>> x2 = f2->pre(lat|:,lon|:,time|:)
>> ;printVarSummary(x2)
>> x2!0 = "lat"
>> x2!1 = "lon"
>> x2&lat@units = "degrees_north"
>> x2&lon@units = "degrees_east"
>> c = escorc(x1,x2)
>> copy_VarCoords(x2,c)
>> plots(i) = gsn_csm_contour_map_ce(wks,c(:,:),res)
>>
>> end do
>>
>> ypts = (/ 34, 34, 29.5, 29.5, 34/)
>> xpts = (/ 69.3, 74.5, 74.5, 69.3, 69.3/)
>>
>> resb = True ; polyline
>> mods desired
>> resb@gsLineColor = "black" ; color of
>> lines
>> resb@gsLineThicknessF = 1.0 ; thickness
>> of lines
>>
>> pres = True
>> pres@gsnFrame = True
>> pres@gsnPanelLabelBar = True
>> pres@pmLabelBarWidthF = 0.8
>> gsn_panel(wks,plots,(/3,2/),pres)
>> dum = new(4,graphic)
>>
>> do j = 0,3
>> dum(j)=gsn_add_polyline(wks,plots,xpts(j:j+1),ypts(j:j+1),resb)
>> end do
>> draw(plots)
>> frame(wks)
>> end
>>
>>
>>
>> _______________________________________________
>> 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

-- 
------------------------------------------------------
Jonathan Vigh	
Postdoctoral Fellow, Advanced Study Program
National Center for Atmospheric Research
Mesoscale&  Microscale Meteorology Division
Foothills Lab 3 - Rm. 3081
Office: 303-497-8205
Cell:   720-347-9337
------------------------------------------------------

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Dec 22 10:32:36 2010

This archive was generated by hypermail 2.1.8 : Wed Dec 22 2010 - 16:10:23 MST