"""
绘制三维图形
"""
import numpy as np
import matplotlib.pyplot as plt
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.sin(R)
ax.plot_surface(X,Y,Z,rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'))
ax.contourf(X,Y,Z,zdir='z', offset=-2, cmap='rainbow')
ax.set_zlim(-2,2)
plt.show()
说明:
rstride=1, cstride=1指的是row,col的跨度,一般都是1,然后彩虹色。
将1改为5效果如下