NCL Home> Application examples> Maps and map projections || Data files for some examples

Example pages containing: tips | resources | functions/procedures

NCL: Drawing locations of data values via markers or lines

The gsn_coordinates procedure takes an existing plot and a data variable, and draws the plot again but with markers or grid lines drawn at the grid locations of your data.

It will query your data variable and/or the resource list in order to get the grid location information, by looking for one of the following:

  • Coordinate arrays attached to the data variable
  • Special "lat2d" / "lon2d" attributes attached to the data variable
  • Special "lat1d" / "lon1d" attributes attached to the data variable
  • gsnCoordsLat / gsnCoordsLon attached to the res resource list
  • gsnCoordsX / gsnCoordsY attached to the res resource list

This procedure recognizes several additional special attributes:

  • gsnCoordsAttachAsLines - by default, the grid locations will be drawn as filled dots, unless this resource is set to True, in which case lines will be drawn.

  • gsnCoordsAttach - by default, when this procedure is called, the plot is drawn immediately, the markers or lines are drawn on top, and the frame is advanced. If this resource is set to True, then the markers or lines are only attached to the plot, and nothing gets drawn. You will need to call draw and frame yourself. This is useful if you need to panel plots with coordinate locations added. See datagrid_6.ncl below.

  • gsnCoordsMissingColor / gsnCoordsNonMissingColor - By default, if you are drawing the locations as markers, they will all get drawn in black. These resources allow you to set colors for marker locations where your data is or isn't missing.

For other examples of using gsn_coordinates, see the Plotting data on a map examples page.

datagrid_1.ncl: This script draws the lat/lon locations of a global rectilinear grid in three ways: 1) as points, 2) as lines, and 3) as every 3rd line.
datagrid_2.ncl: This script shows how to add lines at locations of three WRF-ARW variables which are on different lat/lon grids:

  hgt [south_north | 197] x [west_east | 206]
  u   [south_north | 197] x [west_east_stag | 207]
  v   [south_north_stag | 198] x [west_east | 206]
Since WRF data is on a curvilinear grid you must read the lat/lon values off the file and attach them as special lat2d / lon2d attributes before calling gsn_coordinates.
datagrid_3.ncl: This example plots the same three WRF grids as the previous example, except it plots them on one map plot that has been zoomed in so you can see the grid better. The HGT lat/lon locations are drawn in dots instead of lines.

datagrid_4.ncl: This script draws a WRF lat/lon grid on top of a filled contour plot of the HGT variable, using the native map projection defined on the WRF output file.
datagrid_5.ncl: This script draws the lat/lon grid of a temperature variable on a regional rectilinear grid using two methods: 1) black lines and 2) red markers where the data is missing, and black markers where it isn't.
datagrid_6.ncl: This script uses the USA_adm0.shp shapefile (downloaded from to mask data on a rectilinear grid over the United States. Both the original data and the masked data have the lat/lon locations drawn as markers, with the red points indicating missing data locations.

The special gsnCoordsAttach resoure is set to True, so the markers are actually attached to both plots. This is so we can panel the plots later and have the markers still be visible.

shapefiles_16.ncl: This is another example of drawing data locations after you've masked the data against a shapefile.

In this case, dummy data is used to create a coarse (32 x 64) grid and fine (64 x 128) grid. Both grids are masked against a Mississippi River Basin shapefile. Finally, gsn_coordinates is used to draw the lat/lon grid as a set of markers on all four plots.

See examples shapefiles_21.ncl and See examples shapefiles_22.ncl for more examples of masked shapefiles with data locations drawn.

datagrid_7.ncl: This script draws markers for a contour plot that's not over a map. Since the data is rectilinear, the coordinate arrays are already attached to "u". Note that the cnFillOpacityF resource is set to 0.5 to draw the filled contours partially transparent.
contour1d_1.ncl: The data in this example is a one-dimensional (1D) array with corresponding 1D lat/lon arrays.

Since the "pw" data already has lat1d / lon1d attributes attached for creating the contour plot, it's easy to plot the data locations using gsn_coordinates.

ESMF_regrid_32.ncl: Drawing lat/lon locations on plots of regridded data can be useful for debugging purposes. This particular example regrids WRF output temperature data to both a 1.0 and 0.5 degree grid, and compares them in a panel plot.
datagrid_8.ncl: This script shows how gsn_coordinates can be used to help guess at the correct map projection parameters needed to plot data in a native lambert conformal map projection.

When plotting native data over an LC projection, you need to provide a meridian and two parallels:


These values are usually available on the same file that the data is on. If not, then you may need to guess at these values.

To help with the guessing process, you can draw the lat/lon grid of your data using the given map projection parameters. If the lat/lon grid lines are parallel and perpendicular to the rectangle that the plot is drawn in, then you likely have the correct parameters.

In this example, the meridian and one of the parallel values was provided, but the other parallel value didn't look right. We used a do loop to loop through four possible values, and drew the lat/lon lines as thick purple lines for each plot.

If you click on the leftmost plot (res@mpLambertParallel1F=34), you'll see the farmost right vertical grid line sticking out in the lower right corner, so this is likely not the correct value. The second-from-the-left plot (res@mpLambertParallel1F=35) is a little better, but the vertical line still sticks out a little in the lower right. In the rightmost plot (res@mpLambertParallel1F=37), the vertical lines stick out at the upper left corner.

The second-from-the-right plot (res@mpLambertParallel1F=36) seems to be the best fit. Of course, you could fine tune this example by trying other values close to 36, like 35.8, 35.9, 36, 36.1, etc.

datagrid_9.ncl: This example shows how to draw the vertex edges of an MPAS mesh. Work in progress
geo_1_660.ncl: This example shows how to use gsn_coordinates to draw the mesh edges of a the second image from the previous example, except it was generated using gsn_coordinates to draw the mesh edges and cell centers. This functionality was added in NCL V6.6.0 which is scheduled for release in January 2019.