代码内容
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
'''让下面的都在一个框框里面'''
ax = Axes3D(fig)
'''绘制3D空间(坐标轴)'''
X = np.arange(-4,4,0.25)
Y = np.arange(-4,4,0.25)
X,Y = np.meshgrid(X,Y)
'''把x,y绘制对应到底面的面上去'''
R = np.sqrt(X**2 + Y**2 + np.exp(np.pi))
Z = np.tanh(R)
ax.plot_surface(X,Y,Z,rstride=1,cstride=1,cmap=plt.get_cmap('rainbow'))
'''绘制3D cmap又一种方法'''
ax.contourf(X,Y,Z,zdir='z',offset=0.99987,cmap='summer')
'''顺便在某平面画个等高线 zdir是决定从哪个方向压下去'''
plt.show()
图顺利出来,警告内容:
MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. Pass the keyword argument auto_add_to_figure=False and use fig.add_axes(ax) to suppress this warning. The default value of auto_add_to_figure will change to False in mpl3.5 and True values will no longer work in 3.6. This is consistent with other Axes classes.
ax = Axes3D(fig)
如何解决警告的内容?