1

I use the following code to alter the appearance of the axis of a 3d-plot in matplotlib:

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.grid(False)
ax.xaxis.pane.set_edgecolor('black')
ax.yaxis.pane.set_edgecolor('black')
ax.zaxis.pane.set_edgecolor('black')
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
plt.show()

However, one spine is missing. How can I activate the missing spine (black line on the left)? The code above produces this plot:

enter image description here

sunnytown
  • 1,844
  • 1
  • 6
  • 13
  • The missing border seems to be clipped away depending on viewing angle. See also [this blogpost](https://dawes.wordpress.com/2014/06/27/publication-ready-3d-figures-from-matplotlib/) where the author writes *"I found that the visibility of parts of the pane edge depends on the viewing angle. I found that setting the view to `ax1.view_init(elev=10, azim=135)` worked to see all the edge lines."* – JohanC Dec 31 '21 at 13:05
  • Thanks, so it's a bug. Is there any solution without changing the view angle? – sunnytown Dec 31 '21 at 13:19

1 Answers1

2

I developed this program for you, it works fine:

from scipy import integrate
import pylab
from mpl_toolkits.mplot3d import axes3d, art3d

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
fig = plt.figure()
fig.set_edgecolor("green")

ax = fig.add_subplot(projection='3d')
ax.grid(False)
def lims(mplotlims):
    scale = 1.021
    offset = (mplotlims[1] - mplotlims[0])*scale
    return mplotlims[1] - offset, mplotlims[0] + offset
xlims, ylims, zlims = lims(ax.get_xlim()), lims(ax.get_ylim()), 
lims(ax.get_zlim())
i = pylab.array([xlims[0], ylims[0], zlims[0]])
f = pylab.array([xlims[0], ylims[0], zlims[1]])
p = art3d.Poly3DCollection(pylab.array([[i, f]]))
p.set_color('black')
ax.add_collection3d(p)

ax.xaxis.pane.set_edgecolor('black')
ax.yaxis.pane.set_edgecolor('black')
ax.zaxis.pane.set_edgecolor('black')


ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False

plt.show()

Output:

enter image description here