You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disclaimer2: I am aware that matplotlib cannot deal with 3D occlusion and that for that type of issue I should use Mayavi. This is a different situation.
What I'm trying to achieve is to plot a line on top of a surface. The line is only on "this" side of the surface so my expectation was that I could control what comes in front by adjusting the zorder. Unfortunately, it seems as if the zorder is not behaving as expected.
In my experiment below, the only thing that seems to be affected by the zorder is the line plot, which goes in front of the scatter if zorder>=3 (regardless of the zorder of the scatter points) and it goes in front of the surface if zorder>=4 (regardless of the zorder of the surface).
As far as I can tell, matplotlib is simply ignoring the zorder for the scatter and the surface and setting them fixed values. Is there a way around this, i.e. to force the zorder for the surface and the scatter?
In the result of the MWE below. The line is above the surface but the scatter points are below the surface.
Code for reproduction
importnumpyasnpfrommpl_toolkits.mplot3dimportAxes3Dimportmatplotlib.pyplotaspltcos=np.cossin=np.sinarccos=np.arccospi=np.pidefgetxyz(in_theta,in_phi,scale=1.0):
x=scale*sin(in_theta)*cos(in_phi)
y=scale*sin(in_theta)*sin(in_phi)
z=scale*cos(in_theta)
returnx,y,z# ============== SCRIPT ================# Initialize Figurefig=plt.figure(figsize=(8,8),dpi=100)
ax=fig.add_subplot(111, projection='3d')
ax.set_aspect("equal")
# Plot Sphere Surface-plotNS=10Sx,Sy,Sz=getxyz(*np.mgrid[0:pi/2:NS*2j, 0:pi/2:NS*2j])
ax.plot_surface(Sx,Sy,Sz,rstride=2,cstride=2, color=(0.5,0.5,0.5,0.7),zorder=100)
# Make a line on the sphereNl=20Lx,Ly,Lz=getxyz(np.linspace(pi/3,pi/4,Nl),np.linspace(0,pi/3,Nl))
# Plot Scatterax.scatter(Lx,Ly,Lz,s=30,c='k',depthshade=False,zorder=500)
# Plot Lineax.plot(Lx,Ly,Lz,'r-',zorder=4)
ax.view_init(30, 45)
fig.savefig("test.png")
# plt.show()
Bug report
Bug summary
Disclaimer: I posted this in stackoverflow in case there is a workaround, but I believe it to be a bug or maybe a potential feature that would be very useful. Link here: https://stackoverflow.com/questions/56010933/matplotlib-plot3d-surface-line-scatter-plot-how-to-define-z-order
Disclaimer2: I am aware that matplotlib cannot deal with 3D occlusion and that for that type of issue I should use Mayavi. This is a different situation.
What I'm trying to achieve is to plot a line on top of a surface. The line is only on "this" side of the surface so my expectation was that I could control what comes in front by adjusting the zorder. Unfortunately, it seems as if the zorder is not behaving as expected.
In my experiment below, the only thing that seems to be affected by the zorder is the line plot, which goes in front of the scatter if zorder>=3 (regardless of the zorder of the scatter points) and it goes in front of the surface if zorder>=4 (regardless of the zorder of the surface).
As far as I can tell, matplotlib is simply ignoring the zorder for the scatter and the surface and setting them fixed values. Is there a way around this, i.e. to force the zorder for the surface and the scatter?
In the result of the MWE below. The line is above the surface but the scatter points are below the surface.
Code for reproduction
Actual outcome
https://i.stack.imgur.com/QJnof.png
Expected outcome
The idea would be to be able to bring the scatter dots in front of the surface and the line by changing their zorder values.
Matplotlib version
The text was updated successfully, but these errors were encountered: