XY (line) Type Plot Templatesgsn_csm_xy
gsn_xy (generic routine)
gsn_xy (generic routine)
xyLineThicknesses allows the user to change the thickness of individual lines in the array, while xyLineThicknessF allows the user to set one value that changes the thickness of all the lines in the array.
You can set the color of your lines with xyLineColors.
First Plot: Use predefined dash pattern: xyDashPatterns allows you to select from one of the following dashed patterns. Note that in a multi-line plot, the default is to make the first line the first pattern, the second line the second pattern etc.
trYReverse, reverses the y-axis.
Second Plot: Create your own dash pattern: As of NCL version 4.2.0.a030, you can make your own marker using NhlNewDashPattern. You give the function a string representing the pattern you want. See script and function documentation for examples. The function returns a dash pattern index that can be used with xyDashPatterns
Second Plot: Make your own marker
As of NCL version 4.2.0.a030, you can make your own marker using NhlNewMarker. You give the function the character and font table you want the marker taken from, and provide sizing and placement values. The function returns a marker index that can be used with xyMarkerColor.
gsn_polyline is the function that will add the polyline. Note that you can not panel plots made with this function. If you need to panel, use gsn_add_polyline. See polyline example 4 on how to use this function. It is slightly different than gsn_polyline.
ind returns the indexes of the input where it is True.
ispan allows the user to create an integer array. This is frequently used when creating the x-array in an XY plot.
gsn_csm_xy2 allows the user to draw two lines each with their own separate Y-axis.
tmXUseBottom= False, tmXTOn, and tmXTLabelsOn allows the user to set a top X-axis in addition to the bottom X-axis. We could have done the same for the right Y-axis using the corresponding YR resources.
tmXMajorGrid= True, Turns on the
grid in the x-direction.
tmXMajorGridThicknessF, controls the line thickness.
tmXMajorGridLineDashPattern, controls the type of line. Similar resources exist for the y-axis grid.
This example also demonstrates how to set the precision of an
tmYRLabelsOn turns on the labels, tmYUseLeft = False, will sure than any settings, such as precision used by the left axis are not used for the right axis. tmYRAutoPrecision = False, turns off the auto precision for the right axis and finally, tmYRPrecision sets the desired precision.
Method 1: Break the line up into different parts and draw as it it were multiple lines. This way you can specify the color and style of each segment.
Method 2: Similar to example 14, but demonstrates how to create a polygon around a portion of a xy line in order to highlight it.
xyLabelMode = "Custom", allows the user to label a line.
tmXBMajorOutwardLengthF set to 0.0 will draw the tickmarks inward. You must do this for the minor tickmarks as well. Separate resources exist for each axis.
See the legend example page for a description of the legend resources used in this example as well as other legend resources.
Before V5.0.0, the undocumented function "fill_xy2" was used to accomplish this. With V5.1.0, you can now do this using the special "gsn" resource gsnXYFillColors. Both methods are illustrated in this script.
After all the plot elements are created and attached, this script calls maximize_output to maximize the size of the plot in the frame. This only applies for PS/PDF output.
Several "tmYR" tickmark resources are set to control the ticks and the labels on the right Y axis. The default is to put tickmarks and labels only on the left axis. To put them on the right only, you need to set (for one) tmYUseLeft to False. The resource tmYRLabelDeltaF is set to 2.0 to move the labels further away from the right tickmarks, and tmYRLabelJust is set to "CenterRight" to right-justify the labels.
The first frame shows how to fill areas between adjacent curves that don't intersect, using gsnXYFillColors. This resource can be an array of color indexes or color names, and should have one fewer colors than you have curves.
The second frame shows how to fill areas between adjacent curves that intersect, using gsnXYAboveFillColors and gsnXYBelowFillColors to indicate the colors where one curve is above or below the other curve. For any areas you don't want filled, you can use "transparent" or -1.
Available in version 5.1.0 and later.
The first frame shows an XY plot created using gsn_csm_xy2, and the second frame shows a new curve that was added to the plot represented by the right Y axis.
The point of this example is to show how to use the relatively unknown NhlAddData function to add data to an XY plot. This example uses some of the normally-hidden object-oriented features of NCL to create a new data object, and to set additional resources.
You need to use the special "xy2" attribute that is returned from the gsn_csm_xy2 call.
To add curves to the data space of the right Y axis, you need to use the special "xy2" attribute that is returned from the gsn_csm_xy2 call.
The second image is identical, except with thicker plot elements for a nicer looking image. It was created by "unique_10_thicker.ncl".
This is a typical plot that people see in papers of paleoclimate studies.
This example was contributed by Yi Wang of PNNL.
gsn_csm_xy3 is used to draw the first three curves. The fourth curve is created separately, and added as an annotataion using NhlAddAnnotation The Y axis for the fourth curve is also added as an annotation. This allows to you resize the original "plot", and all four curves will be resized accordingly.
Michel Mesquita of the Bjerknes Centre for Climate Research gave us permission to include his script.
This script was contributed by Haoming Chen from LASG/IAP in Beijing, China.
This script was contributed by Birgit Hassler (NOAA).
The first frame of this example shows the default plot with a linearly-spaced Y axis, and the second frame shows how to make this axis irregularly spaced.
The "ypts" variable is the array that defines the new spacing on the Y axis.
The first frame uses predefined dashed patterns, which can be hard to distinguish if you make the lines really thick.
The second frame uses dash patterns created with the NhlNewDashPattern function.
Here's what the strings look like for the predefined dash patterns:
0 "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" 1 "$$$$__$$$$__$$$$__$$$$__$$$$__$$$$__$$$$__$$$$__" 2 "$__$__$__$__$__$__$__$__$__$__$__$__$__$__$__$__" 3 "$$$$__$__$$$$__$__$$$$__$__$$$$__$__$$$$__$__" 4 "$$$$__$_$__$$$$__$_$__$$$$__$_$__$$$$__$_$__" 5 "$$_$$_$$_$$_$$_$$_$$_$$_$$_$$_$$_$$_$$_$$_$$_$$_" 6 "$$$_$$$_$$$_$$$_$$$_$$$_$$$_$$$_$$$_$$$_$$$_$$$_" 7 "$_$$_$_$$_$_$$_$_$$_$_$$_$_$$_$_$$_$_$$_$_$$_$_$$_" 8 "$_$$$_$_$$$_$_$$$_$_$$$_$_$$$_$_$$$_$_$$$_$_$$$_" 9 "$$_$$$$_$$_$$$$_$$_$$$$_$$_$$$$_$$_$$$$_$$_$$$$_" 10 "$$$$_$$_$_$$_$$$$_$$_$_$$_$$$$_$$_$_$$_$$$$_$$_$_$$_" 11 "$$__$$__$$__$$__$$__$$__$$__$$__$$__$$__$$__$$__" 12 "$$$$$$__$$$$$$__$$$$$$__$$$$$$__$$$$$$__$$$$$$__" 13 "$$$_$$$__$$$_$$$__$$$_$$$__$$$_$$$__$$$_$$$__" 14 "$$___$$___$$___$$___$$___$$___$$___$$___$$___$$___" 15 "$_$___$_$___$_$___$_$___$_$___$_$___$_$___$_$___" 16 "$$$$$_____$$$$$_____$$$$$_____$$$$$_____$$$$$_____"
In order to do this, it is necessary to create 4 XY plots, each with two curves and two items in its legend. The legend for each plot is moved to the right or left slightly so they don't overlap. The plots are then all "connected" into one plot using the overlay procedure.