直到取消注释 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' object has no attribute '_edgecolors2d'
我原以为可能是因为我在2D图中玩弄了plt.legend()的framealpha
和frameon
参数,但我重新启动了运行时(我正在使用Google Colab Jupyter笔记本),清除了所有变量,问题仍然存在。
这个错误的可能原因是什么?