Jac*_*ern 5 python matplotlib mplot3d
在取消注释该plt.legend()
行之前,以下代码段可以正常工作:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = np.linspace(-1, 1)
y = np.linspace(-1, 1)
X, Y = np.meshgrid(x, y)
Z = np.sqrt(X**2 * Y)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, label='h=0')
ax.plot(np.zeros_like(y), y, np.zeros_like(y), label='singular points')
# plt.legend()
plt.show()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
'Poly3DCollection' object has no attribute '_edgecolors2d'
我以为原因可能是我在2d图中使用了plt.legend()framealpha
和frameon
参数,但是我重新启动了运行时(我在Google Colab Jupyter Notebook中工作),清除了所有变量,然后问题仍然存在。
是什么导致此错误?
Ami*_*ana 19
嗨,我发现这是一个错误,库开发人员仍在试图解决它。我在git 中找到了有关该问题的以下线程
他们给出的建议是获得绘图
surf = ax.plot_surface(X, Y, Z, label='h=0') surf._facecolors2d=surf._facecolors3d surf._edgecolors2d=surf._edgecolors3d
如果 matplotlib 版本是 matplotlib 3.3.3 试试下面
surf._facecolors2d = surf._facecolor3d surf._edgecolors2d = surf._edgecolor3d
小智 10
截至matplotlib 3.3.3
、_facecolors3d
和_edgecolors3d
不存在。所以,而不是这个:
surf._facecolors2d = surf._facecolors3d
surf._edgecolors2d = surf._edgecolors3d
Run Code Online (Sandbox Code Playgroud)
这会导致类似的结果AttributeError
,试试这个:
surf._facecolors2d = surf._facecolor3d
surf._edgecolors2d = surf._edgecolor3d
Run Code Online (Sandbox Code Playgroud)
由于代表性较低,我不得不将此作为答案,而不是评论。
归档时间: |
|
查看次数: |
1144 次 |
最近记录: |