pytutorial/numpy/mesh_grid/README.md
David Rotermund af6fdac1c1
Create README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
2023-12-19 12:00:18 +01:00

935 B

Meshgrid

{:.no_toc}

* TOC {:toc}

The goal

Questions to David Rotermund

numpy.meshgrid

numpy.meshgrid(*xi, copy=True, sparse=False, indexing='xy')

Return a list of 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.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 1, 100)
y = np.linspace(0, 1, 100)

xv, yv = np.meshgrid(x, y)

plt.imshow(xv, cmap="hot")
plt.xlabel("x axis")
plt.ylabel("y axis")
plt.title("xv")
plt.show()

plt.imshow(yv, cmap="hot")
plt.xlabel("x axis")
plt.ylabel("y axis")
plt.title("yv")
plt.show()

image0

image1