I'm plotting three-dimensional scatter data grouped into three distinct clusters: one is red, one is green, and one is blue.
The problem I'm experiencing is that when the clusters are rotated in-line with the camera, the viewer does not display the clusters in the spatial order you would normally expect (i.e.: the closest cluster should be occluding those farthest from camera). Instead I see that the stacking priority is determined by color (in this case R->G->B) with the red having priority over the green and the green over the blue.
In the following link, the red cluster should be hidden behind the green not over it. https://i.sstatic.net/n0fCC.jpg
So, what controls the stacking order (arrangement) of the scatter data and how can I change it so that the display priority is given in order of proximity to the camera?
from pylab import *
from numpy import *
from mpl_toolkits.mplot3d import axes3d
fig = figure()
ax = fig.gca(projection='3d')
# plot points in 3D
class1 = 0.5 * random.standard_normal((200,3))
ax.plot(class1[:,0],class1[:,1],class1[:,2],'o')
class2 = 0.7 * random.standard_normal((700,3)) + array([5,4,0])
ax.plot(class2[:,0],class2[:,1],class2[:,2],'o')
class3 = 0.3 * random.standard_normal((200,3)) + array([2,3,2])
ax.plot(class3[:,0],class3[:,1],class3[:,2],'o')
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.set_zlabel('Z-axis')
plt.show()
See these limitations of matplotlib for 3D plotting.
I don't think there is a solution if you need a dynamically good view (i.e. the ability to move the plot). If you don't, you can pass the zorder keyword to all plotting calls and achieve the result you intend to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With