Matplotlib 3.4 gca()方法已经弃用,替代方法

今天在应用最小二乘回归方法对多维进行科学试验时候,出现一个警告

C:Users	imAppDataLocalTempipykernel_263802953945051.py:23: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
  ax = fig.gca(projection ='3d')


import numpy as np

def fm(p):

x,y = p

return np.cos(x) + 0.7*x +np.sin(y) + 0.05*y**2

x = np.linspace(0,100,50)

y = np.linspace(0.100,50)

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

Z = fm((X,Y))

x =X.flatten()

y= Y.flatten()

#print(x)

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(figsize=(10,10))

ax = fig.gca(projection ='3d')

surf = ax.plot_surface(X,Y,Z,rstride=2,cstride=2,cmap='coolwarm',linewidth=0.3,antialiased=True)

ax.set_xlabel('x')

ax.set_ylabel('y')

ax.set_zlabel('f(x,y)')

fig.colorbar(surf,shrink=0.5,aspect=0.5)


后查资料得出解决方法把

ax = fig.gca(projection ='3d')

替换为

ax = fig.add_subplot(projection='3d')


然后再在jupyter notebook里运行就不报错了。


展开阅读全文

页面更新:2024-03-24

标签:多维   方法   科学   资料

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top