NCL Home> Application examples> Plot techniques || Data files for some examples

Example pages containing: tips | resources | functions/procedures

Time labels

There are many ways to customize an X or Y axis to have nice time labels. One way is to set the tmXBMode/tmXBValues/tmXBLabels and/or tmYLMode/tmYLValues/tmYLLabels yourself.

The user-contributed functions time_axis_labels, ut_string (added in V5.2.0), and cd_string (added in V6.1.0) provide several options for customizing time labels on an X or Y axis, and will take care of setting the necessary "tm" resources for you. These functions were contributed by Arindam Chakraborty and Carl Schreck.

time_labels_1.ncl: This example shows various ways to create nicely formatted time labels on the X axis. One method sets the tmXBFormat resource to "f" to remove trailing zeros from the year labels. The other method sets the resources tmXBMode, tmXBValues, and tmXBLabels to create "Jan 2000" type of labels. The function code "~C~" is used to force a carriage return in these labels.
time_labels_2.ncl: This example shows how to use the time_axis_labels procedure to generate nice time labels on the Y axis.

time_axis_labels recognizes special "ttm" resources for customizing time labels. In this example, "ttmFormat" is set to "%d %c" to generate labels "1 Jul", "11 Jul", etc. This procedure will internally set the necessary "tm" resources for you. (Which was done by hand in the first example above.)

time_labels_3.ncl: This example shows how to use the time_axis_labels procedure to generate nice time labels for a WRF plot. The wrf_times_c function has to be used first to convert the WRF "Times" character variable into a numeric array.

time_labels_4.ncl: This example shows what happens if you try to plot data that has one axis represented by time values of "YYYYMM". You will get a "spline approximation" warning, due to the irregularly-spaced nature of time:

   _NhlCreateSplineCoordApprox: Attempt to create spline
   approximation for X axis failed: consider adjusting 
   trXTensionF value
Also, your X axis will be labeled with index values instead of time values.

To fix the time values, use cd_inv_calendar in conjunction with time_axis_labels to produce nicely-formatted time values on the X axis.