NCL Home> Application examples> gsn_csm graphical interfaces || Data files for some examples
Example pages containing:
tips | resources | functions/procedures
XY Plots
XY Plotting Functions
gsn_csm_xy
gsn_xy (generic routine)
gsn_csm_xy2
gsn_csm_xy3
gsn_csm_x2y2
gsn_csm_x2y
gsn_polyline
gsn_add_polyline
Related Pages
- Bar chart - how to turn XY plots into bar plots
- Legends - how to add legends to an xy plot
- Drawing primitives - how to add additional lines, text, markers, and polygons to a plot
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.
xyMarkLineMode allows the user to set the "mode" ("Lines", "MarkLines", "Markers") for all lines. You can change colors and marker styles with xyMarkerColors and xyMarkers.
There are numerous marker styles to choose from. See example 4 for an example of creating your own markers.
A Python version of the two curve XY plot projection is available here.
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
A Python version of the profile plot projection is available here.
First Plot: Use predefined markers
xyMarkLineModes, xyMarkers, xyMarkerColor, and
xyMarkerSizeF are used to control the markers in an XY plot.
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.
A Python version of the scatter plot projection is available here.
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.
gsnYRefLine, gsnAboveYRefLineColor, gsnBelowYRefLineColor will draws a reference line and determines the color for the shaded regions.
vpHeightF and vpWidthF will changes the aspect ratio of the plot. Since we stretch the plot, we also moved it slightly to the left using vpXF.
trYMinF, trYMaxF can be used to limit the extent of the y-axis. There are corresponding resources for the x-axis.
A Python version of this projection in color is available here.
tmXBMode = "Explicit", tmXBValues, adn tmXBLabels will allow the user to explicitly set the tick mark labels for the bottom x (XB) axis. Similar resources exist for the left y (YL) axis etc.
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.
A Python version of the xy_7_2 projection is available here.
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.
As in example 6 above, we can now use the explicitly labeling resources tmXTMode = "Explicit", tmXTValues, and tmXTLabels to label the axis.
There are numerous fonts/character sets in NCL. As this example demonstrates, you change between sets by using a function code. The default code is a ":", but since this is a character that people often put into their strings, we recommend changing that to a non-used character like a "~". You can change this on the fly as demonstrated in this example, or in your .hluresfile.
A Python version of this projection is available here.
This example also demonstrates how to set the precision of an additional axis.
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.
A Python version of both projections is available here.
tmYRBorderOn = False, will turn off a border while tmYROn = False, will turn off the tickmarks for that side. Corresponding resources exist for the other sides.
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.
A Python version of the first example profile plot projection is available here.
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.
A Python version of this projection is available here.
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.
In the first frame, the gsn_csm_xy function detects that your X values are the multi-dimensional array, so the gsnXYFillColors are applied between the X curves.
The second frame shows how to fill areas between adjacent curves that intersect, using gsnXYRightFillColors and gsnXYLeftFillColors to indicate the colors where one curve is to the right or left of the next curve. These resources were added in NCL V6.4.0.
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.
- first frame - the original two-curve plot
- second frame - the third curve in its own plot
- third frame - the third curve plot overlaid on the two-curve plot
Note that additional code had to be added to turn off the titles before drawing the three-curve plot.
The third curve is in the same data space as the blue curve of the two-curve plot, which is represented by the "xy2" attribute. When you call overlay, you need to use this attribute as the base plot to overlay on.
The first frame shows an XY plot created using gsn_csm_xy2, and the second frame shows how to add a curve to the data space represented by both Y axes using gsn_add_polyline.
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 annotation 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).
gsn_csm_blank_plot won't be available until version 6.0.0, so it's included in this example.
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.
The Y location of each plot is changed by setting the vpYF value. The highlighting is done with calls to gsn_add_polygon, gsn_add_polyline, and gsn_add_text.