[Matplotlib-users] Transparency for pcolor slices in Axes3D plot

Dear matplotlib users/developers,

` I struggle to set some transparency in an Axes3D plot with
series of 2D-slices generated with pcolor. In spite of trying to
set alpha, all the slices remain opaque. I’ve just posted the
issue on stackoverflow ,
where you can see an illustration of the problem. Would someone
have a workaround?

  `

import numpy as np

``import matplotlib.pyplot as plt``

``from mpl_toolkits.mplot3d import Axes3D``

``          from matplotlib.collections import

PolyCollection``

````

``X, Y = np.meshgrid(x,y)``

````

``fig = plt.figure()``

``ax = fig.gca(projection='3d')``

````

``alpha = 0.8``

````

``for i in range(len(islices)):``

``     im = ax.pcolor(X,Y,u[islices[i],:,:])

#,alpha=alpha)``

``     #im.set_facecolor((0, 0, 1, alpha))``

``````             

ax.add_collection3d(im,zs=xslices[i],zdir=‘y’)````

    ``

plt.show()

Thank you in advance.
````

Thibaut Appel writes:

Dear matplotlib users/developers,

I struggle to set some transparency in an Axes3D plot with series of
2D-slices generated with pcolor. In spite of trying to set alpha, all the
slices remain opaque. I've just posted the issue on stackoverflow <https://stackoverflow.com/questions/60776103/how-to-enforce-transparency-for-pcolor-slices-within-axes3d-scope>,

That image -- the way the 0.45 layer is drawn as if it's in front of
the 0.40 layer -- illustrates a problem I've always had with Axes3D.
I didn't have trouble making them transparent, but Axes3D sometimes
makes the wrong decision about which layer is in front, so you get
the wrong translucency. I have an illustration of the problem at
http://shallowsky.com/blog/programming/matplotlib-3d-collection.html
I always meant to file a bug on it but never did.

Thibaut, I'm not sure why your alpha values aren't working, but you
might want to compare my demo (linked from that page) to see
what's different, since the alpha is working for me.

        ...Akkana

···

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

The ordering problem is well-known and is a limitation of the 2D rendering engine of matplotlib. I call them “Escher Effects”. No need to file a bug report, there are plenty of discussions on ways to mitigate it in specific instances, but ultimately, if you need a complex 3D scene, you may need to use a true 3D rendering tool like mayavi or others. This is discussed on the mplot3d main page.

I hope that helps!

Ben Root

···

On Fri, Mar 20, 2020 at 11:55 AM Akkana Peck akkana@shallowsky.com wrote:

Thibaut Appel writes:

Dear matplotlib users/developers,

I struggle to set some transparency in an Axes3D plot with series of

2D-slices generated with pcolor. In spite of trying to set alpha, all the

slices remain opaque. I’ve just posted the issue on stackoverflow <https://stackoverflow.com/questions/60776103/how-to-enforce-transparency-for-pcolor-slices-within-axes3d-scope>,

That image – the way the 0.45 layer is drawn as if it’s in front of

the 0.40 layer – illustrates a problem I’ve always had with Axes3D.

I didn’t have trouble making them transparent, but Axes3D sometimes

makes the wrong decision about which layer is in front, so you get

the wrong translucency. I have an illustration of the problem at

http://shallowsky.com/blog/programming/matplotlib-3d-collection.html

I always meant to file a bug on it but never did.

Thibaut, I’m not sure why your alpha values aren’t working, but you

might want to compare my demo (linked from that page) to see

what’s different, since the alpha is working for me.

    ...Akkana

Matplotlib-users mailing list

Matplotlib-users@python.org

https://mail.python.org/mailman/listinfo/matplotlib-users