3.6版本后的matplotlib使用plot_surface作图无效果的解决方法
在使用3.6.2版本的matplotlib使用以下代码进行作图时发现plot_surface无效果,显示的图上只有坐标,没有数据。
1 | fig = plt.figure() |
结果如图:

百度了一圈发现大家都是这样写的,并没有问题;又在官方文档里转了半天也没找到解决方法,遂将matplotlib的版本回退到3.5.1,再次运行上述代码,发现这次居然有效果了,并且提示了以下内容:

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.
这说明上述的用法在最新版的matplotlib中已被弃用,将
1 | fig = plt.figure() |
改为
1 | fig = plt.figure() |
就可以正常显示了。
END