I am trying to generate the top/bottom of a cylindrical surface. I was able to obtain the lateral surface here: Generating a Cylindrical Surface with np.outer. I would like to use np.outer again for consistency. I thought I understood the answers in the link however if I understood correctly then the following should work:
R = 5
h = 5
u = np.linspace(0, 2*np.pi, 100)
x = R * np.outer(np.ones(np.size(u)), np.cos(u))
y = R * np.outer(np.ones(np.size(u)), np.sin(u))
z = h * np.outer(np.ones(np.size(u)), np.ones(np.size(u)))
however in my plots, no surface is generated. Am I still not using np.outer correctly? Why is no surface generated?
There is no visible disk because all the points which you are creating have exactly the same distance to the center and surface which spans between "inner circle" and "outer circle" is infinitely thin. In order to see the disk, radius needs to vary between 0 and your desired value (5 in the example).
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
R = np.linspace(0, 5, 100)
h = 5
u = np.linspace(0, 2*np.pi, 100)
x = np.outer(R, np.cos(u))
y = np.outer(R, np.sin(u))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x,y,h) # z in case of disk which is parallel to XY plane is constant and you can directly use h
fig.show()