-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Alpha parameter doesn't work in bar3d #9559
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
Comments
I wonder if this is backend-dependent. I can't reproduce this problem using
TkAgg (I don't have Qt5 installed on this machine)
…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. |
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? |
This is my source tree where I have 2.0 checked out. Can you confirm on your side? |
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:
|
Ah, of course, Py2 (I can confirm it works there for me too). |
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 I am not familiar with how matplotlib handles |
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 Admittedly this is only a temporary hack. The matplotlib developers should be able to come up with a rigorous patch. |
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. |
To follow up on the previous comment, matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py Lines 2383 to 2384 in 8168210
For me with Python 3, Internally, matplotlib/lib/mpl_toolkits/mplot3d/art3d.py Lines 694 to 704 in 4536165
Whereas using, p._facecolors3d = matplotlib.colors.to_rgba_array(
p._facecolors3d, p._alpha)
p._edgecolors3d = matplotlib.colors.to_rgba_array(
p._edgecolors3d, p._alpha) and combining it with the fix proposed in #4067 (comment) (I was getting the corresponding error anyway), p._facecolors2d = p._facecolors3d
p._edgecolors2d = p._edgecolors3d appears to make transparency work as expected. |
Yes, I think this is a duplicate of #10237. The issue is ultimately with
and some of that magic must not work as expected. |
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! |
Bug report
I have the same problem than on this Stackoverflow webpage :
Code for reproduction
Actual outcome
The bar on the plot are not transparent at all but they should be.
Matplotlib version
print(matplotlib.get_backend())
): Qt5AggMatplotlib have been installerd from conda.
The text was updated successfully, but these errors were encountered: