-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Axes3D/add_collection3D( LineCollection ): Z-Index forces incorrect drawing order #3884
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
Indeed, there is a bug, but it isn't quite like what you think is happening. The collection object gets a single zorder value in order to determine its drawing order in relation to other artists, but it is up to the collection object to determine the draw order for its own elements. This is the best we can do given Matplotlib's layering engine for rendering. The Poly3DCollection has some sophisticated logic to try and properly layer its elements on the fly, and that is why you see it work fine in the example. This was necessary because incorrectly layered polygons are very obvious. Looking over the code for Line3DCollection, it does not have any of this sophistication. I am presuming that it is because incorrectly layered lines are not nearly as visually obvious compared to polygons. I didn't even realize that one can make something like a polygon collection out of a line collection! @mdboom , Is that even a supported feature of LineCollections, or is that an accident of design? If that is a supported feature of LineCollections, then I will see if I can utilize the same code in Poly3DCollection in Line3DCollection, which should fix this problem. |
Thanks for your rapid reply. Are there any tests you'd like me to try to help you out? |
Confirming this still exists in 1.5.3. @WeatherGod did you end up getting any guidance from @mdboom? |
Has there been any progress on this? We use it in our research papers, for example see Fig 2 in this paper: |
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! |
Checking this - bug is still present, in Anaconda / Python 3.11, Spyder 5.4.3, matplotlib 3.7.1 ![]() (Unrelated) - the demo script now produces an error near the start;
Result (python 3.11): Had to replace line with Here is the modified demo script to reproduce this problem:
|
Hello,
I believe I have found a bug in using
add_collection3d()
to produce plots like in this example:'Matplotlib Tutorial / Polygon plots / Axes3D.add_collection3d' -- sorry, you have to click "Polygon Plots" due to the page's inability to target properly
(The actual demo script is here. )
The bug is exhibited when you use a
LineCollection
instead ofPolyCollection
(the example uses PolyCollection)My guess is that, for a 3DLineCollection, the Z-Index controls the drawing order, such that the highest valued Z-Index is always obscured by the lower-valued Z-indices, even when you rotate the plot (azimuth angle).
I have modified the aforementioned
PolyCollection
example (which is bugless) to plot the same data via aLineCollection
instead, which immediately reproduces the plotting issue.Here is the example of a

Collection3D
of aLineCollection
(note the viewing Azimuth angle), rotated to look as expected, with the appropriate Lines obscuring those behind them:However, with the plot rotated 90 degrees (Azimuthal angle), we get an Incorrect drawing (the Yellow curves should be at the Back):

To reiterate, this problem does Not occur with a
PolyCollection
passed toadd_collection3d()
, but does when passing aLineCollection
.Please let me know if you're able to reproduce the problem, and thanks for your time & patience with a first-time poster.
Here is the aforementioned example script, modified to plot a
LineCollection
instead (and alpha set to 1.0 to aid visual clarity).The text was updated successfully, but these errors were encountered: