PyNGL Home > Functions > Miscellaneous


Given min/max values and the maximum number of steps desired, calculates an array of "nice" equally-spaced values through the data domain.

Available in version 1.3.1 or later.


min_out,max_out,step_size = Ngl.nice_cntr_levels(start, end, outside=True,
     max_steps=15, cint=None, returnLevels=False, aboutZero=False)



Data value at which to start.


Data value at which to end.


Controls whether the return min/max fall just outside or just inside the data domain. If outside=True:

  min_out <= min < min_out + step_size
  max_out >= max > max_out - step_size

If outside=False:

  min_out >= start > min_out - step_size 
  max_out <= end < max_out + step_size 


The maximum number of equally-spaced points desired between start and end.


If specified, the contour interval is set to this, and the max/min bounds, based on outside, are returned.


If True, an additional argument is returned that is a numpy array containing the contour levels.


If True, makes sure that the contour levels will be centered about zero.


Given the minimum and maximum values of a data domain, and the maximum number of steps desired, this function returns "nice" minimum and maximum values, and a spacing, that can be used to generate an array of equally-spaced values through the domain.

The outside flag controls whether the max and min are inside or outside the data range.

Optionally, if returnLevels=True, the levels are returned such that:

where n is an integer < max_steps:

min_out + n * step_size == max_out

with no remainder.

If start==end, or a contour interval cannot be computed, then "None" is returned.

This algorithm mimics the NCL function "nice_mnmxinvtl"; however, the optional cint argument was added to facilitate a user-specified specific interval, and aboutZero allows you to request symmetric values about zero.

See Also

Ngl.contour, Ngl.contour_map


See (output) in the gallery.

cmin,cmax,cint = Ngl.nice_cntr_levels(-23.1, 70.7)

Answer should be:

(-30., 80., 11.)
cmin,cmax,cint = Ngl.nice_cntr_levels(-23.1, 70.7, outside=False)
Answer should be:

(-20., 70., 9.)
cmin,cmax,cint,levels = Ngl.nice_cntr_levels(-11.1, 26.7, outside=True, cint=5.0,returnLevels=True)
Answer should be:

(-15.0, 30.0, 5.0) array([-15., -10.,  -5.,   0.,   5.,  10.,  15.,  20.,  25.,  30.]))
cmin,cmax,cint,levels = Ngl.nice_cntr_levels(-2.1,7.1,outside=True,cint=3.0,returnLevels=True,aboutZero=True)
Answer should be:

(-9.0, 9.0, 3.0, array([-9., -6., -3.,  0.,  3.,  6.,  9.]))