Skip to content

Wrong drawing Poly3DCollection #16633

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

Closed
sdorof1 opened this issue Mar 2, 2020 · 4 comments · Fixed by #16648
Closed

Wrong drawing Poly3DCollection #16633

sdorof1 opened this issue Mar 2, 2020 · 4 comments · Fixed by #16648
Milestone

Comments

@sdorof1
Copy link

sdorof1 commented Mar 2, 2020

Drawing 3D polygon with the code:

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.set_xlim((0, 5))
ax.set_ylim((0, 5))
ax.set_zlim((0, 5))
x = [1,2,3, 3,2,1]
y = [2,1,2, 2,1,2]
z = [1,1,1, 2,2,2]
v = [list(zip(x, y, z))]
pc = Poly3DCollection(v)
ax.add_collection3d(pc)

Leads to the following result on scene rotation:

2

While the polygon should looks like this:

1

Matplotlib version

  • Operating system: Ubuntu 16.04.6 LTS
  • Matplotlib version: 3.1.2
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipympl.backend_nbagg
  • Python version: 3.8.1
  • Jupyter version (if applicable): 1.0.0
  • Other libraries:
@timhoffm
Copy link
Member

timhoffm commented Mar 3, 2020

This is currently a limitation of mplot3d, which is not really a 3D renderer, tries to heuristically create a 3D impression by drawing 2D stuff.

The points a in the (projected) correct position in both cases, as you could see if you just draw the edges but no filling. However, the filling is just a 2D filling of the projection. This is in general not what one would expect from a filled 3D polygon.

Speaking of which, in the general case, creating a filling for a 3D polygon is a non-trivial task and there is no unique solution. Therefore, for now, I'd declare that filling of 3D polygons is not officially supported and whether or not a filled 3D polygon looks right is pure chance.

grafik

@timhoffm timhoffm added this to the unassigned milestone Mar 3, 2020
@anntzer
Copy link
Contributor

anntzer commented Mar 3, 2020

I wouldn't even call this a limitation of mplot3d: the polygon is simply not well defined at all. It could just as well be two parallel triangular faces connected with a rectangle.

In general I think PolyCollection3D should only support triangular faces, possibly with some shortcut to split rectangles into pairs of triangles or more triangulation helpers.

@timhoffm
Copy link
Member

timhoffm commented Mar 3, 2020

In general I think PolyCollection3D should only support triangular faces, possibly with some shortcut to split rectangles into pairs of triangles or more triangulation helpers.

I have a slightly different point of view. A polygon is just a sequence of (connected) points. It actually does not have any faces. In 2D you can easily fill the enclosed area, in 3D there is no well-defined contained area.

If you want to have surfaces, you should use plot_trisurf instead. It can already handle triangulation.

@anntzer
Copy link
Contributor

anntzer commented Mar 3, 2020

Indeed, I should have said "don't support filled Poly3DCollections with non-triangles".

@tacaswell tacaswell modified the milestones: unassigned, v3.2.1 Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants