matplotlib--3d显示

from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
def f(x,y):
    return(1-x/2+x**5 + y**3)*np.exp(-x**2-y**2)


n=50
x = np.linspace(-3, 3, n)
y = np.linspace(-3, 3, n)

X, Y = np.meshgrid(x,y)

fig=plt.figure()

ax = Axes3D(fig)

ax.plot_surface(X, Y, f(X,Y), cmap=plt.get_cmap('rainbow'))
ax.contourf(X, Y, f(X,Y), zdir='z',offset=-0.8, cmap='rainbow')
plt.contourf(X, Y, f(X,Y), 80, alpah = 0.75, cmap='rainbow')


plt.xlim((-3,3))
plt.ylim((-3,3))
plt.xticks(())
plt.yticks(())
plt.colorbar()
plt.show()
matplotlib--3d显示_第1张图片

你可能感兴趣的:(matplotlib)