Return coordinate matrices from coordinate vectors.
Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays x1, x2,..., xn.
Changed in version 1.9: 1-D and 0-D cases are allowed.
x1, x2,..., xn : array_like
1-D arrays representing the coordinates of a grid.
indexing : {‘xy’, ‘ij’}, optional
Cartesian (‘xy’, default) or matrix (‘ij’) indexing of output. See Notes for more details.
New in version 1.7.0.
sparse : bool, optional
If True a sparse grid is returned in order to conserve memory. Default is False.
New in version 1.7.0.
copy : bool, optional
If False, a view into the original arrays are returned in order to conserve memory. Default is True. Please note that sparse=False, copy=False will likely return non-contiguous arrays. Furthermore, more than one element of a broadcast array may refer to a single memory location. If you need to write to the arrays, make copies first.
New in version 1.7.0.
X1, X2,..., XN : ndarray
For vectors x1, x2,..., ‘xn’ with lengths Ni=len(xi) , return (N1, N2, N3,...Nn) shaped arrays if indexing=’ij’ or (N2, N1, N3,...Nn) shaped arrays if indexing=’xy’ with the elements of xi repeated to fill the matrix along the first dimension for x1, the second for x2 and so on.
In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
x = np.linspace(1.0, 6.0, 5)
y = np.linspace(12.0, 15.0, 3)
In [3]:
X,Y = np.meshgrid(x,y, indexing='xy')
indexing='xy'
(default)
In this case X
and Y
are of size: (len(y), len(x))
For the above example:
X.shape = (3,5)
Y.shape = (3,5)
If indexing='ij'
:
In this case X
and Y
are of size: (len(x), len(y))
For the above example:
X.shape = (5,3)
Y.shape = (5,3)
In [4]:
X.shape
Out[4]:
In [5]:
X
Out[5]:
In [6]:
Y.shape
Out[6]:
In [7]:
Y
Out[7]:
Notice that the starting point (X,Y)[0,0]
is in the top-left corner.
In [8]:
im = plt.imshow(X)
cb = plt.colorbar(im)
In [9]:
im = plt.imshow(Y)
cb = plt.colorbar(im)