Skip to content
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

Overlapping 3D objects #12620

Closed
Chutlhu opened this issue Oct 24, 2018 · 7 comments
Closed

Overlapping 3D objects #12620

Chutlhu opened this issue Oct 24, 2018 · 7 comments
Milestone

Comments

@Chutlhu
Copy link

Chutlhu commented Oct 24, 2018

Bug report

When plotting a 3D plane, a segment and a few points, there are visualization issues:
The 'filling' of the plane cover the line and the points

import mpl_toolkits.mplot3d as a3
import matplotlib.pylab as plt
import numpy as np    

fig = plt.figure()
ax = a3.Axes3D(fig)

# create an orizontal plane
corners = [[0,0,0],[0,5,0],[5,5,0],[5,0,0]]
tri = a3.art3d.Poly3DCollection([corners], alpha=1)
tri.set_color('w')
tri.set_edgecolor('k')
ax.add_collection3d(tri)

# plot a vector
ax.plot([2,2],[2,2],[0,4], c = 'r')

# plot some points
ax.scatter([1,3],[1,3],[1,3], c = 'r')

ax.set_xlim([0, 5.0])
ax.set_ylim([0, 5.0])
ax.set_zlim([0, 2.5]);

plt.show()

output figure
image

expected output:
the red segment should at [2, 2, 0] in the middle of the plane. It looks as it is 'under' it

stackoverflow thread

Matplotlib version

  • Operating system:
  • Matplotlib version: 3.0.0
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5, GTK and WX
  • Python version: 3.6.6

Installed with pip

@WeatherGod
Copy link
Member

https://matplotlib.org/mpl_toolkits/mplot3d/faq.html#my-3d-plot-doesn-t-look-right-at-certain-viewing-angles

TL;DR: mplot3d is useful, but is limited by the z-ordering rendering engine of matplotlib. It is incapable of properly constructing a scene with multiple elements that have overlapping bounding boxes. There are some tricks to help mitigate this somewhat, but it can never truely be solved.

@ImportanceOfBeingErnest
Copy link
Member

Thanks.
The main point being that this is a regression to 2.2.3. Bisects to #9094

@WeatherGod
Copy link
Member

Oy, seriously? I don't see any unit tests in that PR, and I don't think anybody asked for my review of the mplot3d portions. I would have pointed out that the fundamental design of mplot3d prevents having an axis above anything.

@tacaswell tacaswell modified the milestones: v3.0.1, v3.0.x Oct 25, 2018
@tacaswell
Copy link
Member

Pushed out as I don't think this is going to be fixed in the next 6-12 hours.

@tacaswell
Copy link
Member

Sorry @WeatherGod This looks like my mistake to merge 🐑

@anntzer
Copy link
Contributor

anntzer commented Oct 29, 2018

Looking at it again I am tempted to close this as "not worse than the known issues with mplot3d".

In 2.2, things would "work" if you had only two PolyCollections, but not three:

import mpl_toolkits.mplot3d as a3
import matplotlib.pylab as plt
import numpy as np

fig = plt.figure()
ax = a3.Axes3D(fig)

# create an orizontal plane
corners = [[0,0,0],[0,5,0],[5,5,0],[5,0,0]]
tri = a3.art3d.Poly3DCollection([corners], alpha=1)
tri.set_color('w')
tri.set_edgecolor('k')
ax.add_collection3d(tri)
corners = [[0,0,1],[0,5,1],[5,5,1],[5,0,1]]
tri = a3.art3d.Poly3DCollection([corners], alpha=1)
tri.set_color('w')
tri.set_edgecolor('k')
ax.add_collection3d(tri)
corners = [[0,0,2],[0,5,2],[5,5,2],[5,0,2]]
tri = a3.art3d.Poly3DCollection([corners], alpha=1)
tri.set_color('w')
tri.set_edgecolor('k')
ax.add_collection3d(tri)

# plot a vector
ax.plot([0,0],[5,5],[-10,10], c = 'r')

# plot some points
ax.scatter([1,3],[1,3],[1,3], c = 'r')

ax.set_xlim([0, 5.0])
ax.set_ylim([0, 5.0])
ax.set_zlim([0, 2.5])

plt.show()

test
because the PolyCollections would get assigned increasing zorders -- 0, 1, 2 and thus at some point crosses the (default) zorder of Line2D's (which is 2). The change in #9094 is that the numbering of PolyCollection zorders now start higher (2.5) and is now above the default Line2D zorder from the beginning.

The solution in either case is to set the zorder of the line to a high enough value, e.g. ax.plot(..., zorder=10) works in all cases.

@anntzer anntzer removed their assignment Oct 29, 2018
@jklymak
Copy link
Member

jklymak commented Oct 31, 2018

Based on the above solution, I'm closing. Agree this is suboptimal, and indeed may have changed in 3.0.0, but I don't think we should bother fixing it given the limitations on draw order in mplot3d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants