有没有办法让 gca 方法从 plotly 工作?

问题描述 投票:0回答:1

配置:

  • 苹果操作系统
  • 对代码
  • python-3.x

错误:

代码:

fig = plt.figure(figsize=(10, 6))
ax = fig.gca(projection='3d')
surf1 = ax.plot_surface(X, Y, Z, rstride=2, cstride=2, cmap=mpl.cm.coolwarm, linewidth=0.5, antialiased=True) # Plots the original function surface 
surf2 = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2, label='regression') # Plots the regression surface
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('f(x, y)')
ax.legend()
fig.colorbar(surf, shrink=0.5, aspect=5)

报错信息:

TypeError                                 Traceback (most recent call last)
Cell In\[61\], line 2
1 fig = plt.figure(figsize=(10, 6))
2 ax = fig.gca(projection='3d')
3 surf1 = ax.plot_surface(X, Y, Z, rstride=2, cstride=2, cmap=mpl.cm.coolwarm, linewidth=0.5, antialiased=True) # Plots the original function surface
4 surf2 = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2, label='regression') # Plots the regression surface

TypeError: FigureBase.gca() got an unexpected keyword argument 'projection'
<Figure size 1000x600 with 0 Axes>

我正在尝试获取此图像:(请参见下图)

python-3.x macos plotly
1个回答
0
投票

我目前使用的解决方法如下:

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

给出以下代码:

fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(projection='3d')
surf1 = ax.plot_surface(X, Y, Z, rstride=2, cstride=2, cmap=mpl.cm.coolwarm, linewidth=0.5, antialiased=True) # Plots the original function surface 
surf2 = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2, label='regression') # Plots the regression surface
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('f(x, y)')
ax.legend()
fig.colorbar(surf, shrink=0.5, aspect=5)

但我更愿意找到使 gca 工作的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.