New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transparecy of figures in 3D plots (mplot3d) #1541
Comments
Just to confirm, which version of matplotlib are you using? |
|
I can quickly note that the rgb2hex() function seems to ignore the alpha part (which would explain your first issue):
|
ok, but I was assuming that it was the tri.set_alpha(0.3) that would do that... |
and set_alpha() should work, I just need to track down why it doesn't. I have no clue if rgb2hex() should or should not ignore the alpha part. I have an idea why set_alpha() doesn't work, but I need to double-check a few things. |
Btw, just in case it's of any help, I tried to modify the alpha value by brute force, i.e. tri._alpha = 0.5 and didn't work either. |
ok |
Ok, I confirmed my suspicions. This is... complicated, to say the least. As a "design feature", particularly with scatter plots, 3d polygons in a collection that are further away are given a higher transparency to help with the illusion of depth. The alpha values have to be recalculated on the fly as one interacts with the plot (via the facecolors and edgecolors attributes) and the tri._alpha is explicitly set to None internally. Try interacting with the plot when you successfully set the alpha value. IIRC, it will drop the given alpha (although I think I fixed that bug when I fixed an issue of the colors going bland after the initial draw). Now that I am looking at this problem with more experienced eyes, I wonder if this can be more elegantly addressed. |
well, I don't know if I have understood you right... with the script I'm using (the example code was a simplification of it) I represent ~100 polyhedrons, and with the rgba tuplas everything seems right (I can move the figure around and the transparency doesn't go away). In any case, for me it is enough to use it like that, I just reported in case it was necessary to change something in the code. And well, if the set_alpha method does nothing, I'd suggest to omit it, and put in the documentation that the way to set transparency is using rgba tuplas, and any other alternative working method I don't know of. Thanks for your time anyway, cheers! |
Probably haven't solved them all, but this gets most of them.
Probably haven't solved them all, but this gets most of them.
Hi,
I'm trying to do a 3D plot with semi-transparent polyhedrons using mplot3d, but the setting of the alpha value has no effect. Here's the code I'm trying,
import mpl_toolkits.mplot3d as a3
import matplotlib.colors as colors
import pylab as pl
ax = a3.Axes3D(pl.figure())
color = colors.rgb2hex(sp.rand(3))
color = (0.,1.,0.,0.2) # but this works!
side1 = [[0.,0.,0.],[0.,0.,1.],[0.,1.,1.],[0.,1.,0.]]
tri = a3.art3d.Poly3DCollection([side1])
tri.set_facecolor(color)
tri.set_edgecolor('k')
tri.set_alpha(0.2) # HAS NO EFFECT
ax.add_collection3d(tri)
side2 = [[0.,0.,0.],[1.,0.,0.],[1.,1.,0.],[0.,1.,0.]]
tri = a3.art3d.Poly3DCollection([side2])
tri.set_facecolor(color)
tri.set_edgecolor('k')
tri.set_alpha(0.2)
ax.add_collection3d(tri)
pl.show()
Apparently, the tri.set_alpha sentences have no effect, and the pannels show solid. Changing color for an rgba tupla works, nonetheless (the commented line).
Cheers,
Ruyman
The text was updated successfully, but these errors were encountered: