To create an XY plot using GSUN, your NCL script should look similar to the code below. Calls to the GSUN functions are bold-faced.
; The following "load" command is necessary to load in the GSUN ; functions and procedures. load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl" begin npts = 100 ; Number of points in curve. x = ispan(0,npts-1,1) ; Generate integers from 0 to npts-1. y = sin(6.28*x/(npts-1)) ; Generate a sine curve. wks = gsn_open_wks("x11","xy_example") ; Open a workstation for ; which to draw graphics. xyres = True ; Indicate we want to set some resources. xyres@xyLineColor = "2" ; Change the curve color to index 2 (red). xy = gsn_xy(wks,x,y,xyres) ; Create and draw the XY plot. ; This function also advances the frame. end
The above NCL script should produce the following graphical output (click on frame to see it enlarged):
How to change the default value of a resource
To change the default value of a resource for use by a GSUN plotting function, first create a logical variable with any name you want and set its value to "True." Then, for each resource whose value you want to change, make the resource name an attribute of the logical variable you just created and set this attribute equal to the value you want to change the resource to.(For more information about attributes in NCL, see the "attributes" section in the GSUN documentation.)
For example, in the NCL script above, we changed the curve color from its default value of 1 (the foreground color) to a value of 2 (red). To do this, we created a logical variable called xyres and set its value to "True". Then, since the resource for changing the curve color is xyLineColor, we created an attribute of xyres called xyLineColor and set its value to 2.
In the next release of NCAR Graphics software, it will be possible to set color resources using named colors in addition to using color index values. For more information on using named colors in NCL, see the article "From AliceBlue to YellowGreen: Name those colors!" in this issue.