1

In this question we are shown how to plot (among many other things) a sphere: Python/matplotlib : plotting a 3d cube, a sphere and a vector?

It's very nice but I would like to plot the wireframe sphere in such a way that the parallels and meridians that are outside the line of vision (hidden by the sphere itself) don't appear. Is that possible with a python script?

Thanks.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
David
  • 1,155
  • 1
  • 13
  • 35

1 Answers1

2

The idea of a wireframe plot is to make is see-through such that features behind the object are still visible.
So instead of a wireframe you probably want to plot a surface plot:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")

# draw sphere
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.plot_surface(x, y, z, color="w", edgecolor="r")

plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • Excuse me, I know I have accepted your answer, but what I get is a 2d surface, white and as red line the exterior circumference. I copied the code, do you know what's happening? – David Oct 09 '17 at 11:19
  • Do you also not get a wireframe plot when using the wireframe code? Which version of matplotlib are you using? – ImportanceOfBeingErnest Oct 09 '17 at 12:33
  • I didn't have problems drawing the wireframe. I'm using version 1.5.3 of matplotib. – David Oct 09 '17 at 12:57
  • 1
    The example above is produced with version 2.0. In version 1.5 you need to add the arguments `rstride=1, cstride=1` to `plot_surface`. – ImportanceOfBeingErnest Oct 09 '17 at 13:03