python绘制三维图
程序员文章站
2022-07-13 09:21:29
...
python绘制三维图
用python绘制3维图片,示例为关于公式
如果报错:Unknown projection ‘3d’
则必须要加上:from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline
# f(x,y) = (x^2+y-11)^2+(x+y^2-7)^2
def himmelblau(x):
return (x[0]**2+x[1]-11)**2+(x[0]+x[1]**2-7)**2
x = np.arange(-6,6,0.1)
y = np.arange(-6,6,0.1)
X,Y = np.meshgrid(x,y)
print('x,y maps',X.shape,Y.shape)
Z = himmelblau([X,Y])
fig = plt.figure('himmelblau')
ax = fig.gca(projection='3d')
ax.plot_surface(X,Y,Z)
ax.view_init(60,-30)
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()
上一篇: python三维图绘制
下一篇: python画三维图