3D图片的绘制

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D


def himmelblau(x):
    return (x[0]**2 + x[1]-1)**2 + (x[0]+x[1]**2-1)*2


x = np.arange(-6,6,1)
y = np.arange(-6,6,1)
X,Y = np.meshgrid(x,y)
print(X.shape)
print(Y.shape)

Z = himmelblau([X,Y])
fig = plt.figure('himmelblau')
ax = Axes3D(fig)
ax.plot_surface(X,Y,Z)
ax.view_init(60,-30)
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()

你可能感兴趣的:(3D图片的绘制)