Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
Artifacts are common in mplot3d when overlaying several 3D objects
This is stated in the official FAQ,
and there exist some related issues(e.g. this one) as well as SO questions.
The official answer is that mplot3d is not powerful enough to deal with a realistic z-order behavior, so switch to a more powerful framework instead.
In some use cases, we don't need super-realistic z-ordering, yet some control of which objects are plot over which others is important to get a nice look.
For example: My personal (current) use case was plotting some points and lines over a surface in 3D (to represent the evolution of optimization over a surface in a nice 3D figure).
The current behavior of mplot3d is to order collections and patches (set their zorder value) in terms of the minimum z as seen in the current perspective, which gives aweful results in some common scenarios (e.g. when plotting a point on top of the surface, it will often appear behind the surface rather than in front of it).
Worse yet, art3d objects silently accept a 'zorder' argument but then ignore that value in favor of the behavior explained above.
I think it should be possible to provide user-given zorder values to ensure certain objects are in front of others, and then order also in terms of the computed zmin value for the object.
I have created a quick solution that works for me, leveraging an already existing method
set_sort_zpos
(which by the way I couldn't see used in any other place, so I kind of assumed it had this purpose). The commits should be more-or-less self-explanatory.There are some aspects to refine yet, e.g.
_sort_zpos
instead. This way the zorder option would behave in a more expectable way for the user.However, before refining those details I wanted to present the case and get some feedback on this!
PR Checklist