Skip to content

Fix bug "Setting an alpha value to a Poly3DCollection #10237" - #10747

Closed
JZCJackson wants to merge 1 commit into
matplotlib:masterfrom
JZCJackson:my-feature
Closed

JZCJackson wants to merge 1 commit into
matplotlib:masterfrom
JZCJackson:my-feature

Conversation

@JZCJackson

@JZCJackson JZCJackson commented Mar 10, 2018 •

Copy link
Copy Markdown

PR Summary

In order to set alpha successfully. In Poly3DCollection's set_alpha, facecolors3d should equal to facecolors.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

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()

@jklymak jklymak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can combine these two lines. I think it was just a typo.

@ImportanceOfBeingErnest

Copy link
Copy Markdown
Member

Just to get this straight: Are there now two PRs

both trying to fix #10237 simultaneously?

@jklymak

jklymak commented Mar 12, 2018

Copy link
Copy Markdown
Member

Cloing in lieu of the older PR. Thanks @ImportanceOfBeingErnest and @JZCJackson

@jklymak jklymak closed this Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants