Re: Plot a line

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon, 18 Jun 2007 17:57:24 -0600 (MDT)

Nilesh,

If you are using one of the gsn_csm routines, and you want to plot a
straight line, try setting res_at_gsnYRefLine to the Y value of the line
you want to plot.

If you are not plotting a straight line, then gsn_polyline is one way
to go. You didn't give enough information about how you are calling
this function, so I can only guess at what's going on. For starters,
the X and Y values must be in the same data space as the axis values
of your plot, and make sure they are in the right order in the
argument list (x,y).

Secondly, if you are calling gsn_polyline and then drawing the plot,
the plot will get drawn on top of the line, and will possibly cover
it. Make sure gsn_polyline is called *after* the plot is drawn.

Thirdly, make sure that you are not advancing the frame before you
draw the line, otherwise the line will get drawn on the next
frame. You can fix this by setting res_at_gsnFrame to False when you call
your gsn_csm_xxxx plotting function, and then advance the frame after
you call gsn_polyline by calling "frame(wks)".

Below is an example that adds horizontal lines to an XY plot: the
first time using gsn_polyline, and the second time using
gsnYRefLine.

--Mary

----------------------------------------------------------------------

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin
   wks = gsn_open_wks("x11","line")
;
; Create some dummy data.
;
   npts = 500
   x = fspan(0,npts-1,npts)
   y = 500.+ 0.9 * x * sin(0.031415926535898*x)

   xyres = True
   xyres_at_gsnFrame = False
   xyres_at_gsnMaximize = True

;
; Create and draw plot, but don't advance frame just yet.
;
   xy = gsn_csm_y(wks,y,xyres)

;
; Set up some values to add some horizontal lines.
;
   xvalues = (/min(x),max(x)/)
   yvalues = (/ 300, 450, 510, 670, 720, 910/)

   colors = (/"orange","purple","red","blue","brown","green"/)
   nvalues = dimsizes(yvalues)

;
; First way to add lines, using gsn_polyline.
;
   lnres = True
   do i=0,nvalues-1
     lnres_at_gsLineColor = colors(i)
     gsn_polyline(wks,xy,xvalues,(/yvalues(i),yvalues(i)/),lnres)
   end do

   frame(wks)

;
; Second way, using gsnYRefLine.
;
   delete(xyres_at_gsnFrame)
   xyres_at_gsnYRefLine = yvalues
   xyres_at_gsnYRefLineColors = colors

   xy = gsn_csm_y(wks,y,xyres)

end

----------------------------------------------------------------------

--Mary

On Mon, 18 Jun 2007 araligin_at_onid.orst.edu wrote:

> Hi,
>
> I am plotting a time series and want to draw a line at a standard deviation
> of 1. I am using the gsn_polyline to plot it but I am getting nothing plotted
> at the output.
> Let me know and I can provide my code.
>
> Thanking you,
> Nilesh
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jun 18 2007 - 17:57:24 MDT

This archive was generated by hypermail 2.2.0 : Wed Jun 20 2007 - 17:02:19 MDT