python - PyPlot图例: 'Poly3DCollection' object has no attribute '_edgecolors2d'

标签 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()

我收到以下错误: “Poly3DCollection”对象没有属性“_edgecolors2d”

我认为原因可能是我在二维图中使用了 plt.legend() 的 framealphaframeon 参数,但我重新启动了运行时(我正在使用 Google Colab Jupyter Notebook),清除所有变量,问题仍然存在。

什么可能导致此错误?

最佳答案

嗨,我发现这是一个错误,库开发人员仍在尝试解决它。 我在 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

关于python - PyPlot图例: 'Poly3DCollection' object has no attribute '_edgecolors2d' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54994600/

相关文章:

python - 将字符串解析为列 python pandas/xa0 而不是空格

python - Matplotlib-动画 "No MovieWriters Available"

python - 山蟒的 3D 表面图

python - 如何根据从文件读取的数据 z=f(x,y) 在 matplotlib 中制作 3D 绘图

python - 将多个子进程的输出附加到Python中的数组

python - 为什么编译的 python 正则表达式更慢?

python - 如何在图形 Matplotlib 中显示 x 或 y 值?

python - 将长 xticks 分成 2 行 matplotlib

python - 以透视方式绘制以 3D 投影的一系列 2D 图

python - 在 macOS 上找不到 aws-cli