Fix bug "Setting an alpha value to a Poly3DCollection #10237" #10747
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
In order to set alpha successfully. In Poly3DCollection's set_alpha, facecolors3d should equal to facecolors.
PR Checklist
Snippet of code:
In latest version these two cases can not show the transparency of the graph. In my feature branch it has been fixed.
Case 1 (Setting facecolor and alpha individually, facecolor first):
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
x = [1, 0.9, 1, 0]
y = [0, 0.7, 0, 1]
z = [0, 0.8, 1, 0]
verts = [list(zip(x, y, z))]
alpha=0.4
fc = "C0"
pc = Poly3DCollection(verts, linewidths=1)
pc.set_facecolor(fc)
pc.set_alpha(alpha)
ax.add_collection3d(pc)
plt.show()
Case 2 (Setting facecolors and alpha at instantiation):
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
x = [1, 0.9, 1, 0]
y = [0, 0.7, 0, 1]
z = [0, 0.8, 1, 0]
verts = [list(zip(x, y, z))]
alpha=0.4
fc = "C0"
pc = Poly3DCollection(verts, alpha = alpha, facecolors=fc,
linewidths=1)
ax.add_collection3d(pc)
plt.show()