I'm working on a small project in which the end goal is to obtain some surfaces of revolution generated from custom functions. This is an example representation for sin(x):
import numpy as np
import matplotlib.pyplot as plt
np.seterr(divide='ignore', invalid='ignore')
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.linspace(0,np.pi,600) # Setting the left and right boundaries for sin(x)
y = np.linspace(0, 2*np.pi,600)
U,V = np.meshgrid(x,y)
def function(x): # This is where I would like to pass a random function, for now it's just sin(x)
return np.sin(x)
a = np.vectorize(function) # Vectorizing it so I won't get the length-1 arrays converted to python scalars error
b = a(x) # Applied the function element-wise on the x array
X = U
Y = b*np.cos(V)
Z = b*np.sin(V)
ax.set_xlabel('Y axis')
ax.set_ylabel('X axis')
ax.set_zlabel('Z axis')
ax.plot_surface(X, Y, Z)
plt.show()
Giving me the sphere-shaped object that I expected: Solid of revolution of sin(x) Is there a way to convert the surface into a 600x600x600 numpy array for future use?