The following code snippet works fine until I uncomment the plt.legend()
line:
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()
I get the following error:
'Poly3DCollection' object has no attribute '_edgecolors2d'
I thought the cause may have been that I had played around with the framealpha
and frameon
parameters of plt.legend() in 2d plots, but I restarted the runtime (I'm working in a Google Colab Jupyter Notebook), clearing all variables, and the problem persisted.
What might be causing this error?