Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Setting an alpha value to a Poly3DCollection #10237

Closed
Milestone
@ImportanceOfBeingErnest

Description

Trying to create a semitransparentPoly3DCollection fails as shown in the following.

from mpl_toolkits.mplot3d import Axes3Dfrom mpl_toolkits.mplot3d.art3d import Poly3DCollectionimport matplotlib.pyplot as pltfig = plt.figure()ax = Axes3D(fig)x = [0, 1, 1, 0]y = [0, 0, 1, 1]z = [0, 1, 0, 1]verts = [list(zip(x, y, z))]alpha=0.5fc = "C0"# This line fails to give a semitransparent artistpc = Poly3DCollection(verts, alpha = alpha, facecolors=fc, linewidths=1)ax.add_collection3d(pc)plt.show()

It gives the following output, which still has an alpha of 1.

image

Non-Working options

Now one may try several things. The following isnot working:

  • Setting facecolor and alpha individually, facecolor first,

      pc = Poly3DCollection(verts, linewidths=1)  pc.set_facecolor(fc)   pc.set_alpha(alpha)
  • Setting facecolors and alpha at instantiation

      pc = Poly3DCollection(verts, alpha = alpha, facecolors=fc, linewidths=1)

Working options

However, each of the following is correctly giving a semitransparent artist. This would be the expected outcome for any of the above as well.

  • Setting facecolor and alpha individually, alpha first,

      pc = Poly3DCollection(verts, linewidths=1)  pc.set_alpha(alpha)   # Order reversed   pc.set_facecolor(fc)
  • Setting alpha at instantiation, facecolor afterwards

      pc = Poly3DCollection(verts, alpha = alpha, linewidths=1)  pc.set_facecolor(fc)
  • Setting facecolor and alpha at instantiation

      pc = Poly3DCollection(verts, alpha = alpha, facecolor=fc, linewidths=1)

image

It seems there had been a similar bug in previous versions,https://stackoverflow.com/questions/18897786/transparency-for-poly3dcollection-plot-in-matplotlib which was reported to be fixed in the meantime but might have been reintroduced in a newer version.

In the 2D case the following works as expected and produces a semtransparent artist.

from matplotlib.collections import PolyCollectionimport matplotlib.pyplot as pltfig, ax = plt.subplots()x = [0, 1, 1, 0]y = [0, 0, 1, 1]verts = [list(zip(x, y))]alpha=0.5fc = "C0"pc = PolyCollection(verts, alpha = alpha, facecolors=fc, linewidths=1)ax.add_collection(pc)ax.autoscale()plt.show()

[All of the code in this issue has been tested with matplotlib 2.1]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp