Skip to content

Overlapping 3D objects #12620

Closed
Closed

Description

@Chutlhu

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

Activity

  1. WeatherGod commented on Oct 24, 2018

    @WeatherGod
    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.

  2. ImportanceOfBeingErnest commented on Oct 24, 2018

    @ImportanceOfBeingErnest
    Member

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

  3. WeatherGod commented on Oct 24, 2018

    @WeatherGod
    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.

  4. modified the milestones: v3.0.1, v3.0.x on Oct 25, 2018
  5. tacaswell commented on Oct 25, 2018

    @tacaswell
    Member

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

  6. tacaswell commented on Oct 25, 2018

    @tacaswell
    Member

    Sorry @WeatherGod This looks like my mistake to merge 🐑

  7. anntzer commented on Oct 29, 2018

    @anntzer
    Contributor

    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.

  8. removed their assignment
    on Oct 29, 2018
  9. jklymak commented on Oct 31, 2018

    @jklymak
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions