python - Surface disappears in Matplotlib 3D plot -


i'm trying plot sphere segment cut out. think i've created co-ordinates correctly find pan around sliced sphere, inner surface disappears. doing wrong? if @ relevant, python 2.7.3 matplotlib 1.5.1 on opensuse leap 42.1, using backend tkagg.

everything correct. after slight pan right.

code:

from mpl_toolkits.mplot3d import axes3d matplotlib import pyplot pl import numpy np  fig = pl.figure() ax = fig.add_subplot(111, projection='3d')  phi = np.linspace(0.5*np.pi, 2.0*np.pi, 100) theta = np.linspace(0, np.pi, 100)  x = np.outer(np.cos(phi), np.sin(theta)) y = np.outer(np.sin(phi), np.sin(theta)) z = np.outer(np.ones(np.size(phi)), np.cos(theta)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')  r = np.linspace(0.,1.,25) x = np.outer(r, np.sin(theta)) y = 0.*x z = np.outer(r, np.cos(theta)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='g')  ax.view_init(30.,60.) pl.show() 

it turns out such common problem it's mentioned in faq:

my 3d plot doesn’t right @ viewing angles

this commonly reported issue mplot3d. problem – viewing angles – 3d object appear in front of object, though physically behind it. can result in plots not “physically correct.”

unfortunately, while work being done reduce occurance of artifact, intractable problem, , can not solved until matplotlib supports 3d graphics rendering @ core.

in case, can create crude fix plotting 3 quarters of sphere separately. e.g.

from mpl_toolkits.mplot3d import axes3d matplotlib import pyplot pl import numpy np  fig = pl.figure() ax = fig.add_subplot(111, projection='3d')  theta = np.linspace(0, np.pi, 100)  # first quarter phi = np.linspace(0.5*np.pi, 1.0*np.pi, 34) x = np.outer(np.cos(phi), np.sin(theta)) y = np.outer(np.sin(phi), np.sin(theta)) z = np.outer(np.ones(np.size(phi)), np.cos(theta)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')  # second quarter phi = np.linspace(1.0*np.pi, 1.5*np.pi, 34) x = np.outer(np.cos(phi), np.sin(theta)) y = np.outer(np.sin(phi), np.sin(theta)) z = np.outer(np.ones(np.size(phi)), np.cos(theta)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')  # third quarter phi = np.linspace(1.5*np.pi, 2.0*np.pi, 34) x = np.outer(np.cos(phi), np.sin(theta)) y = np.outer(np.sin(phi), np.sin(theta)) z = np.outer(np.ones(np.size(phi)), np.cos(theta)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')  r = np.linspace(0.,1.,25) x = np.outer(r, np.sin(theta)) y = 0.*x z = np.outer(r, np.cos(theta)) ax.plot_surface(x, y, z, rstride=4, cstride=4, color='g')  ax.view_init(30.,60.) pl.show() 

Comments