3

I have managed to create a code that outputs a sphere and a ring around it but the ring doesn't look like its rounding the sphere...
enter image description here

Can anyone save me here?

Code:

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

theta = np.linspace(0, 2.*np.pi, 100)
phi = np.linspace(0, 2*np.pi, 100)
theta, phi = np.meshgrid(theta, phi)
c, a = 10, 0.2
x = (c + a*np.cos(theta)) * np.cos(phi)
y = (c + a*np.cos(theta)) * np.sin(phi)
z = a * np.sin(theta)

fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
ax1.set_zlim(-10,10)
ax1.plot_surface(x, y, z, rstride=5, cstride=5, color='b', edgecolors='b')
ax1.view_init(36, 26)

u = np.linspace(0, 2 * np.pi, 100)

v = np.linspace(0, np.pi, 100)

x2 = 4 * np.outer(np.cos(u), np.sin(v))
y2 = 4 * np.outer(np.sin(u), np.sin(v))
z2 = 10 * np.outer(np.ones(np.size(u)), np.cos(v))

ax1.plot_surface(x2, y2, z2,  rstride=5, cstride=5, color='r')

plt.show()
Mr. T
  • 11,960
  • 10
  • 32
  • 54
  • I think it is [this well-known problem of mplot3d.](https://matplotlib.org/mpl_toolkits/mplot3d/faq.html) They suggest using [Mayavi.](http://code.enthought.com/pages/mayavi-project.html) – Mr. T Apr 07 '18 at 23:02
  • Did you have a look at [How to obscure a line behind a surface plot in matplotlib?](https://stackoverflow.com/questions/41699494/how-to-obscure-a-line-behind-a-surface-plot-in-matplotlib)? – ImportanceOfBeingErnest Apr 07 '18 at 23:42

0 Answers0