python如何画三维图像?
python三维图像输出的代码如下所示:
#画3D函数图像输出
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
import mpl_toolkits.mplot3d
figure=plt.figure()
#ax = Axes3D(figure)
ax=figure.gca(projection="3d")
x1=np.linspace(-6,6,1000)
y1=np.linspace(-6,6,1000)
x,y =np.meshgrid(x1,y1)
z=(x**2+y-11)**2+(x+y**2-7)**2
#ax.plot_surface(x,y,z,rstride=10,cstride=4,cmap=cm.YlGnBu_r)
ax.plot_surface(x,y,z,cmap="rainbow")
plt.show()
输出三维图像如下所示: