Skip to content
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

zorder ignored in mplot3d #14148

Closed
Marriaga opened this issue May 7, 2019 · 3 comments
Closed

zorder ignored in mplot3d #14148

Marriaga opened this issue May 7, 2019 · 3 comments
Milestone

Comments

@Marriaga
Copy link

Marriaga commented May 7, 2019

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

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

cos=np.cos
sin=np.sin
arccos=np.arccos
pi = np.pi

def getxyz(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)
    return x,y,z

# ==============  SCRIPT  ================

# Initialize Figure
fig = plt.figure(figsize=(8,8),dpi=100)
ax = fig.add_subplot(111, projection='3d')
ax.set_aspect("equal")


# Plot Sphere Surface-plot
NS=10
Sx,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 sphere
Nl=20
Lx,Ly,Lz = getxyz(np.linspace(pi/3,pi/4,Nl),np.linspace(0,pi/3,Nl))

# Plot Scatter
ax.scatter(Lx,Ly,Lz,s=30,c='k',depthshade=False,zorder=500)
# Plot Line
ax.plot(Lx,Ly,Lz,'r-',zorder=4)

ax.view_init(30, 45)
fig.savefig("test.png")
# plt.show()

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

  • Operating system: Fedora
  • Matplotlib version: matplotlib==3.0.3
  • Matplotlib backend: TkAgg
  • Python version: Python 3.7.3
  • Other libraries: numpy==1.15.1
@cirosantilli
Copy link

Related, with PR: #14175 | #14508

@3dqi
Copy link

3dqi commented Jul 7, 2021

Zorder is still ignored for 3D plot. matplotlib==3.4.2
:<

@timhoffm
Copy link
Member

timhoffm commented Jul 7, 2021

Yes. #14508 is targeted for 3.5.0.

@timhoffm timhoffm closed this as completed Jul 7, 2021
@QuLogic QuLogic added this to the v3.5.0 milestone Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants