PyNGL Home > Functions > Array manipulators

Ngl.add_new_coord_limits

Adds new minimum/maximum values to X and/or Y coordinate arrays.

Available in version 1.2.0 or later.

Prototype

data_new = Ngl.add_new_coord_limits(
                                    data,
                                    fillvalue=None,
                                    xcoord=None,
                                    ycoord=None,
                                    xmin=None,
                                    xmax=None,
                                    ymin=None,
                                    ymax=None
                                   )

Arguments

data

A two-dimensional array of which you want to add new minimum and/or maximum values to its X and/or Y coordinate arrays.

fillvalue=None

The missing value for data. This value will be used to fill in the new data array at the locations where new minimum/maximum values have been added.

As of version 1.3.0, if data is a masked array, then data.fill_value() will be used. Otherwise, this value must be set if data is not a masked array.

xcoord=None

The X coordinate array, which must be a 1D array of the same length is the second dimension of data. If specified, then at least one of xmin or xmax must also be specified.

ycoord=None

The Y coordinate array, which must be a 1D array of the same length is the first dimension of data. If specified, then at least one of ymin or ymax must also be specified.

xmin=None

The new minimum value to use for the X coordinate array.

xmax=None

The new maximum value to use for the X coordinate array.

ymin=None

The new minimum value to use for the Y coordinate array.

ymax=None

The new maximum value to use for the Y coordinate array.

Return value

data_new

A NumPy array of the same type as data with one or two more elements in the rightmost and/or leftmost dimension.

Description

This function adds new minimum and/or maximum values to the X and/or Y coordinate arrays of a 2D array, and returns a new 2D array and new coordinate arrays. At the locations that the new coordinate values represent, the new 2D array is set to the missing value, fillvalue.

This function is useful if you are generating a contour plot of the data, and you want to add some white space around the plot itself. Normally you would do this by using a combination of the trXMinF, trXMaxF, trYMinF, or trYMaxF resources. However, if your X and/or Y coordinate arrays are irregular, you cannot change your axes limits using these resources. You must instead use this function to force new limits for your coordinate arrays.

Examples

Example 1

For a simple example, run the following script and examine the output.


import numpy
import Ngl

Tmsg   = -999                                    # Missing value
tarray = numpy.array([[1.,2.,3.],[4.,5.,6.]])    # Dummy 2D data
xcoord = numpy.array([10,11,15])                 # X coordinate array
ycoord = numpy.array([5,10])                     # Y coordinate array

print "tarray =\n",tarray
print "xcoord =",xcoord
print "ycoord =",ycoord

print "\nAdd new minimum value to X coordinate array..."
tarray_new,xcoord_new = Ngl.add_new_coord_limits(tarray,Tmsg,xcoord=xcoord,
                                                 xmin=5)
print "tarray_new =\n",tarray_new
print "xcoord_new =",xcoord_new
print "ycoord     =",ycoord

print "\nAdd new minimum/maximum values to Y coordinate array..."
tarray_new,ycoord_new = Ngl.add_new_coord_limits(tarray,Tmsg,ycoord=ycoord,
                                                 ymin=0,ymax=20)
print "tarray_new =\n",tarray_new
print "xcoord     =",xcoord
print "ycoord_new =",ycoord_new

print "\nAdd new minimum/maximum values to X and Y coordinate arrays..."
tarray_new,xcoord_new,ycoord_new = Ngl.add_new_coord_limits(tarray,Tmsg,
                                        xcoord=xcoord,ycoord=ycoord,
                                        xmin=8,xmax=17,ymin=3,ymax=12)
print "tarray_new =\n",tarray_new
print "xcoord_new =",xcoord_new
print "ycoord_new =",ycoord_new

Ngl.end()
For a more complex example that uses masked arrays, see irregular.py.