I am using python3. When I googled, it came out that I should write the following code to write a sphere with matplotlib. However, here we use matrices for x, y, and z as arguments to plot_surface. What kind of calculation does this do internally and plot the graph? If anyone knows, please professor. Thank you.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
# Make data
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = 10 * np.outer(np.cos(u), np.sin(v))
y = 10 * np.outer(np.sin(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax.plot_surface(x, y, z, color='b')
plt.show()
Recommended Posts