2

I'm trying to plot a line through a 3-D surface as a means of indicating the axis. However, this only results in the line being plotted entirely on top of or beneath the surface--changing the zorder does not solve this.

What I'm looking for is for the line to appear as if it were piercing through the surface

My code and output are below:

fig = plt.figure(figsize=(9,9))
ax = plt.axes(projection='3d')

ax.plot_surface(X,Z,Y,
                linewidth=0,
                cmap=cm.jet,
                facecolors=cm.jet(r_3d/max(abs(r_3d.flatten()))),
                edgecolor='none',
                shade=False,
                antialiased=False)

ax.plot([0,0],[-0.3,0.3],[0,0],linewidth=2,c='k')

Example of line plotted on top of surface

Example of line plotted on top of surface

Hand drawn example of my desired output

Hand drawn example of my desired output

1 Answers1

0

I think you can solve this with zorder (example here), though I have not tried specifically with a 3d plot. zorder changes the plotting order, or essentially the depth at which specific items are plotted. Large z orders plot on top and small ones plot in the back, so if you make the 3d item a z order of 1 and the line as z order zero that should work.

bart cubrich
  • 1,184
  • 1
  • 14
  • 41
  • Changing the ```zorder``` is basically an all or nothing switch--either the line is plotted entirely in front of or behind the surface when changing ```zorder``` – Thomas Luckie Nov 26 '19 at 19:20
  • The idea with `zorder` would be to split your surface: at the back draw the complete surface, then draw the line, and then draw the half of the surface that is closest to the viewer. But I think `plot_surface` is not very happy with drawing half surfaces. – JohanC Nov 26 '19 at 21:23
  • You could also just draw one complete 3d surface, and two lines. – bart cubrich Nov 26 '19 at 21:36