Polygons, Polymarkers, and Polylines
polyg_1.ncl:
This code comes from Mark Stevens of CGD NCAR. To teach himself
NCL, he decided to try and plot the climate divisions that are used
by the NCDC. Outstanding job Mark! By the way this is the most
exciting plot to watch as it draws. Each state is done separately.
Can you name each state as it draws?
gsn_polygon_ndc will add polygons in ndc(page) coordinates while gsn_polygon will add them in plot coordinates.
The "climdiv_polygons.nc" netCDF file used in this script is available here (767440 bytes).
polyg_2.ncl:
This is the same code as example one, except that Mark is now
coloring each polygon with a precipitation value.
mpGridAndLimbOn = False, turns off the lat/lon grid.
mpAreaMaskingOn = True, enables area masking. This then allows the map to be divided into different areas by setting the resource mpFillAreaSpecifiers, e.g. (/"Water","Land"/). These designated areas can then be filled by setting the resource mpSpecifiedFillColors to various colors. In this case, they were set to zero to mask them entirely.
polyg_3.ncl:
A plot with poly markers added. You would be able to panel this
plot. There are numerous
marker styles to choose from.
gsn_add_polymarker is the plot interface that will add polymarkers to a plot so that they can be paneled. There is also gsn_polymarker and gsn_polymarker_ndc which adds the polymarkers in page coordinates.
IMPORTANT: note the syntax on the use of this function:
dum1 = gsn_add_polymarker(wks,plot,glon(inds),glat(inds),polyres) . With this function, you need to set it equal to some sort of dummy variable. Do not set it equal to plot like we do in all other cases. Also, if you do panel this type of plot, do not delete that dummy variable or over write it.
polyg_4.ncl:
Draw and fill a box using polylines and polygons
gsn_add_polyline is the plot interface that adds polylines to a plot, and gsn_add_polygon is the plot interface that adds polygons to a plot. This version allows for panelling. There is also gsn_polyline and gsn_polyline_ndc which adds polylines in page coordinates.
gsLineColor = "red", changes the line color to red.
gsLineThicknessF = 2.0, changes the thickness of the line.
gsFillIndex > 0 changes the fill pattern to a pattern (rather than a solid).
gsFillScale changes the density of the fill pattern.
gsLineLabelString = "test", is one method of labeling a box of this type.
polyg_6.ncl:
Demonstrates adding polylines.
The trick with this plot is to create an array of dummy graphic variables. When you use gsn_add_polyline, the result must be a graphic variable. In a loop, you must not over write the dummy variable, which is why we need an array.
polyg_7.ncl:
Demonstrates how to create your own polymarker.
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.
polyg_8.ncl:
This example shows how to plot values at station locations using
different colors and marker sizes for each station point. The station
values are grouped depending on which range of values they fall in,
and then every marker in this group gets the same color and size.
A legend is added at the bottom, using calls to gsn_polymarker and gsn_text_ndc.
polyg_9.ncl:
This example shows how to draw the Meteorological Subdivisions of India, when given the
boundary coordinates for each subdivision in an ascii file. The top panel uses
gsn_add_polyline to draw the subdivision outlines. The
bottom panel uses gsn_add_polygon to fill the subdivisions.
This approach can be used for any boundary one wishes to draw as long as the coordinates are provided. (One should first check that the desired boundary cannot be drawn using the mpOutlineBoundarySets / mpAreaNames / mpOutlineSpecifiers suite of resources.)
In this example a blank base map was used (drawn using gsn_csm_map), but gsn_add_polyline could have been used to add the boundaries to any map with data contours/filled contours that shows India.
polyg_10.ncl:
This example shows how to draw various polylines and polygons on a
several generic tickmark backgrounds to create a series of bar
charts. The gsn_add_polyline and
gsn_add_polygon functions are
used to create the polylines and polygons and gsn_panel is used to panel all the plots
on one frame.
polyg_11.ncl: This example
shows how to draw the political divisions of Brazil. It was
contributed to us by Mateus da Silva Teixeira from CPTEC/INPE, who
gave us permission to include it and the data files. It is based
on example 9 that draws the Indian
subdivisions.
The data files can be downloaded via the estados_brasil.tar tar file. You need to type "tar -xvf estados_brasil.tar" to extract the files.
