Issue
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?
Solution
Hi I found that is a bug still the library developers are trying to figure out it. I have found the following thread about the issue in git
Their suggestion they have given is to get the plotting
surf = ax.plot_surface(X, Y, Z, label='h=0') surf._facecolors2d=surf._facecolors3d surf._edgecolors2d=surf._edgecolors3d
If the matplotlib version is matplotlib 3.3.3 try below
surf._facecolors2d = surf._facecolor3d surf._edgecolors2d = surf._edgecolor3d
Answered By - AmilaMGunawardana
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.