Skip to content

Instantly share code, notes, and snippets.

@dotannn
Created November 21, 2016 16:01
Show Gist options
  • Save dotannn/d01bd4772300df832905255c2a64e702 to your computer and use it in GitHub Desktop.
Save dotannn/d01bd4772300df832905255c2a64e702 to your computer and use it in GitHub Desktop.
python sphere
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = np.outer(np.cos(u), np.sin(v))
y = np.outer(np.sin(u), np.sin(v))
z = np.outer(np.ones(np.size(u)), np.cos(v))
# the equation should be 1/8*x^2 + y^2 + z^2 = 1
ax.plot_surface(math.sqrt(8)*x, y, z, rstride=4, cstride=4, color='b')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment