PyPlot legend: 'Poly3DCollection' object has no attribute '_edgecolors2d'

Update to @AmilaMGunawardana's answer

As of matplotlib 3.3.3, _facecolors3d and _edgecolors3d do not exist. So, instead of this:

surf._facecolors2d = surf._facecolors3d
surf._edgecolors2d = surf._edgecolors3d

that would lead to a similar AttributeError, try this:

surf._facecolors2d = surf._facecolor3d
surf._edgecolors2d = surf._edgecolor3d

I had to make this an answer, instead of a comment, due to low rep.


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