-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: 3D scatter plot flips alpha order depending on depth relative to camera #22861
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
Likely the same as #19787 but we missed handling Alpha in that context correctly. |
@timhoffm Thanks for the response. Do you have any guess on when this bug will be addressed? I imagine if it hasn't come up until now it's not going to be a high priority. |
We have limited core developer resources and mpl_toolkits/mplot3d is only a secondary priority for the core team. Likely this needs someone in the community to pick up and provide a fix. |
Small update: I found that disabling the alpha on the Path3DCollection to_rbga_array call fixes the behavior, (though things get weird if you turn depthshade back on). I haven't tested much to see why/what else this affects, but I thought it was interesting enough to comment.
|
Update: It is clear that the behavior in my original post is being caused by the current normalization method for the depthshading, in combination with the self._alpha value described in my previous post. What is strange is that the color_array in Also, per the comment on the _zalpha function, I have tried my hand at implementing an alpha-scaler which represents the viewing depth instead of the normalized z-depths. The comment, for reference:
To address this I added some code to calculate a "scale" for the view:
Where get_data_scale is defined as:
The self.dscl value is passed when _zalpha is called and is used to calculate the alpha multipliers for the z-depths like so: This produces depth-shading results like so: I think it's not quite where it needs to be yet, since there are situations where everything approaches ~50% transparency (as seen when everything is close to parallel with the screen in the video) instead of approaching full opacity. Please let me know if you have any thoughts/suggestions on what I've found. I'll keep working on improving the depth shading in the meantime. |
The depth shading can be configured in four ways, with the first representing the typically desired behavior:
|
Also, some videos demonstrating the updated behavior with the 'default' depth shading mode described in the previous comment: |
Bug summary
When plotting a 3D scatter plot with multiple alpha values the resulting alpha values that are plotted depend on the order of points relative to the camera. This behavior continues even if depthshade=False is used. The behavior stops if the points are plotted individually using a for loop.
Code for reproduction
Actual outcome
Ex: In the images below you can see the result of slightly rotating the same plot so that one end of the line of points is closer or further from the camera. This causes the list of alpha values to be applied in either the intended order, or the reverse of that order.
Expected outcome
Simply: the 3D scatter plot alpha values when depthshade=False is used should not depend on the depth from the camera.
Additional information
I've seen closed issues where something very similar was fixed for old versions of matplotlib (python 2 era), so it looks like this bug has resurfaced?
Operating system
Ubuntu
Matplotlib Version
matplotlib 3.5.1
Matplotlib Backend
No response
Python version
Python 3.9.5
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: