Some other graphics
1), grayscale
def f(x_, y_):
return (1 - x_ / 2 + x_ ** 5 + y_ ** 3) * np.exp(-x_ ** 2 - y_ ** 2)
n = 5
x = np.linspace(-2, 3, 3 * n)
y = np.linspace(-2, 3, 2 * n)
X, Y = np.meshgrid(x, y)
plt.imshow(f(X, Y))
plt.show()
Wherein the meshgrid()
generated mesh.
Results are as follows:
2), 3D FIG (plot_surface)
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
X = np.arange(-4, 4, 0.25)
Y = np.arange(-4, 4, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X ** 2 + Y ** 2)
Z = np.cos(R)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='hot')
plt.show()
rstride
Fringe spacing in the x-direction, an interval of 0.25 to x, the default value is 1.cstride
Fringe spacing in y direction, a y-direction spacing of 0.25, a default value.
Results are as follows:
3), the amount of field pattern (Quiver)
n = 10
X, Y = np.mgrid[0:n, 0:n]
plt.quiver(X, Y,color = 'R')
plt.show()
np.mgrid()
Generating 2D, 3D matrix: The number of rows is determined by the first parameter np.mgrid, the number of columns is determined by the first parameter np.mgrid, filled by using the broadcast mechanism.
Results are as follows:
4), the contour (contourf, contour)
def f(x_, y_):
return (1 - x_ / 2 + x_ ** 5 + y_ ** 3) * np.exp(-x_ ** 2 - y_ ** 2)
n = 256
x = np.linspace(-1, 3, n)
y = np.linspace(-1, 3, n)
X, Y = np.meshgrid(x, y)
plt.contourf(X, Y, f(X, Y), 4, alpha=.75, cmap='jet')
plt.contour(X, Y, f(X, Y), 4, colors='black', linewidth=.5)
plt.show()
coutour([X, Y,] Z,[levels], **kwargs)
contourf
Draw filled outline:
parameter | Introduction |
---|---|
X, Y | Similar arrays, optional |
FROM | Highly value matrix-like, draw the outline of |
levels | int array or the like, alternatively, determining the number and location of the contour line / area |
Alf | float, optionally, alpha blending value between 0 (transparent) and 1 (opaque) |
cmap | str or colormap, optional |
Colormap | For data values (floating point) converted from the spacer to the respective Colormap RGBA color representation, the data for scaling the spacing viewed |
PS:
When X, Y, Z is a 2-dimensional array, they must have the same shape. If both 1-dimensional array, len (X) Z is the number of columns, while len (Y) is the number of rows in Z.
contour
Draw contour parameters above.
Results are as follows:
Reference Code:
https://github.com/ZhangJiangtao-0108/python in the matplotlib_example.py
file