You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On Tue, Oct 24, 2017 at 11:36 AM, Gonthier Nicolas ***@***.*** > wrote:
Bug report
I have the same problem than on this Stackoverflow webpage
<https://stackoverflow.com/questions/43670867/matplotlib-alpha-transparency-parameter-doesnt-work>
:
*Code for reproduction*
from mpl_toolkits.mplot3d import Axes3Dimport numpy as npimport matplotlib.pyplot as plt
def main():
plt.ion()
rho = np.random.random((4,4))
xpos = np.arange(0,4,1)
ypos = np.arange(0,4,1)
xpos, ypos = np.meshgrid(xpos, ypos)
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(4*4)
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = rho.flatten()
alpha = 0.5
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.bar3d(xpos,ypos,zpos, dx, dy, dz, alpha=alpha, linewidth=0)
plt.show()
input("Press Enter to continue...")
if __name__ == '__main__':
main()
*Actual outcome*
The bar on the plot are not transparent at all but they should be.
*Matplotlib version*
- Operating system: Ubuntu 16.04
- Matplotlib version: 2.0.2
- Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
- Python version: 3.6
Matplotlib have been installerd from conda.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#9559>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-JHdsECYAvny6EA-zXJB6QsOxceXks5svgQCgaJpZM4QEovL>
.
I can reproduce on tkagg and qt5agg (they both use the same renderer anyways so it'd have been a really weird bug if the result was different). This appears to be a regression somewhere between 1.5.0 and 2.0.0.
Bisecting is a pain because a bunch of commits in the middle appear to have completely broken alpha support :/
my though w.r.t. backends is more on the handling of the graphics context and whether or not the alpha gets passed around correctly. Doubtful, I know, but it is the only thing that made sense to me.
The only other possibility that I can think of is if the mpl_toolkits/mplot3d is getting picked up from someplace different than where matplotlib is and is running a different "version" of mplot3d even though different versions of matplotlib are getting tested?
The only possibility I can think of there is dictionary order... but we addressed those issues a long time ago, and usually that had to deal with the order of colliding properties...
Maybe the alpha of the default color is overriding the user's alpha (doubtful...)?
I just ran a small debugging check between Python 2 and Python 3 myself. And indeed I see that the key alpha in Python 2 remains the first key in kwargs, while in Python 3, alpha becomes the last key in kwargs (when zsort and facecolor are added into kwargs).
I am not familiar with how matplotlib handles kwargs with different key orders though. Just offering my observations. Hope they help.
also fixes the issue. But note that both patches only work on Py3.6 as they rely on kwargs conserving kwargs order.
But it's really a problem of Poly3DCollection only updating the facecolors with the alpha if the alpha is already set when the colors are given (and the luck that on Py2, "alpha" comes before "facecolor" in dict iteration order...). Something like
Could be the same issue as #10237 for which there were already 2 attempted fixes, but none made it through yet. The one in #10487 looks promising and should just be a matter of getting merged?
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
WeatherGod commentedon Oct 24, 2017
anntzer commentedon Oct 24, 2017
I can reproduce on tkagg and qt5agg (they both use the same renderer anyways so it'd have been a really weird bug if the result was different). This appears to be a regression somewhere between 1.5.0 and 2.0.0.
Bisecting is a pain because a bunch of commits in the middle appear to have completely broken alpha support :/
WeatherGod commentedon Oct 24, 2017
Well, here is my image using v2.0.0 using TkAgg:
And that is the same as the image I get using v2.0.1 and v2.1.0...
WeatherGod commentedon Oct 24, 2017
my though w.r.t. backends is more on the handling of the graphics context and whether or not the alpha gets passed around correctly. Doubtful, I know, but it is the only thing that made sense to me.
The only other possibility that I can think of is if the mpl_toolkits/mplot3d is getting picked up from someplace different than where matplotlib is and is running a different "version" of mplot3d even though different versions of matplotlib are getting tested?
anntzer commentedon Oct 24, 2017
This is my source tree where I have 2.0 checked out.
Can you confirm on your side?
WeatherGod commentedon Oct 24, 2017
For me, matplotlib and mpl_toolkits/mplot3d match up. They were installed via conda for the v2.0.0, v2.0.1, and v2.1.0 versions I checked.
This for the v2.0.0 install I have:
And this for the v2.1.0 install:
anntzer commentedon Oct 24, 2017
Ah, of course, Py2 (I can confirm it works there for me too).
So it's a Py3-only issue, probably some kwargs ordering...
WeatherGod commentedon Oct 24, 2017
The only possibility I can think of there is dictionary order... but we addressed those issues a long time ago, and usually that had to deal with the order of colliding properties...
Maybe the alpha of the default color is overriding the user's alpha (doubtful...)?
jsh9 commentedon Apr 23, 2018
I just ran a small debugging check between Python 2 and Python 3 myself. And indeed I see that the key
alphain Python 2 remains the first key inkwargs, while in Python 3,alphabecomes the last key inkwargs(whenzsortandfacecolorare added intokwargs).I am not familiar with how matplotlib handles
kwargswith different key orders though. Just offering my observations. Hope they help.jsh9 commentedon Apr 23, 2018
And then I inserted this line
immediately before this location (https://github.com/matplotlib/matplotlib/blob/master/lib/mpl_toolkits/mplot3d/art3d.py#L542), which simply created a new dictionary reversing the key order (so that
alphawas the first key), and I was able to get semi-transparent 3D bars in Python 3.Admittedly this is only a temporary hack. The matplotlib developers should be able to come up with a rigorous patch.
anntzer commentedon Apr 23, 2018
Alternatively, something like
also fixes the issue. But note that both patches only work on Py3.6 as they rely on kwargs conserving kwargs order.
But it's really a problem of Poly3DCollection only updating the facecolors with the alpha if the alpha is already set when the colors are given (and the luck that on Py2, "alpha" comes before "facecolor" in dict iteration order...). Something like
also fails to apply the alpha on Py2.
rth commentedon May 30, 2018
To follow up on the previous comment,
bar3dpasses thealphatoset_alpha,matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
Lines 2383 to 2384 in 8168210
For me with Python 3,
p.set_alpha(wherepis thePoly3DCollectionobject) also has no effect, so the issue is with this method IMO.Internally,
set_alphamostly consists of,matplotlib/lib/mpl_toolkits/mplot3d/art3d.py
Lines 694 to 704 in 4536165
Whereas using,
and combining it with the fix proposed in #4067 (comment) (I was getting the corresponding error anyway),
appears to make transparency work as expected.
ImportanceOfBeingErnest commentedon May 30, 2018
Could be the same issue as #10237 for which there were already 2 attempted fixes, but none made it through yet. The one in #10487 looks promising and should just be a matter of getting merged?
rth commentedon May 30, 2018
Yes, I think this is a duplicate of #10237. The issue is ultimately with
Poly3DCollectionfrom what I saw. It's docstring states,and some of that magic must not work as expected.
github-actions commentedon Apr 21, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
ksunden commentedon Apr 21, 2023
Appears to have been fixed by #13573 (at least that is what closed #10237, which this appears to be a duplicate of)