Matplotlib 3D workaround for plot order

2020-03-25 10:51发布

问题:

I know that matplotlib 3D is not reliable for plotting multiple 3D objects (planes, lines, points) in the right order: please see Matplotlib 3D plot zorder issue and How to draw intersecting planes?. However these questions seem quite old, so the proposed solutions. Thus, I would like to know if there are some new developments, tools, workarounds or hard-coded solutions for the following specific simple scenario:

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()

In this image you can see the visualization issues: the vector it is not starting from the plane, as it should since his intiali point is (2,2,0)