CoCalc Public Filesmisc / cylinder.sagews
Author: Fidel Barrera-Cruz
Views : 169
Compute Environment: Ubuntu 18.04 (Deprecated)
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

# Scatter graph
N = 100
#X = np.random.uniform(-1, 1, N)
#Y = np.random.uniform(-1, 1, N)
#Z = np.random.uniform(-2, 2, N)
#ax.scatter(X, Y, Z)

# Cylinder
x=np.linspace(-1, 1, 100)
z=np.linspace(0, 7, 100)
Xc, Zc=np.meshgrid(x, z)
Yc = np.sqrt(1-Xc**2)

# Draw parameters
rstride = 20
cstride = 10
ax.plot_surface(Xc, Yc, Zc, alpha=0.2, rstride=rstride, cstride=cstride)
ax.plot_surface(Xc, -Yc, Zc, alpha=0.2, rstride=rstride, cstride=cstride)

ax.set_xlabel("$x$")
ax.set_ylabel("$y$")
ax.set_zlabel("$z$")
plt.show()

<mpl_toolkits.mplot3d.art3d.Poly3DCollection object at 0x7f3293d329d0> <mpl_toolkits.mplot3d.art3d.Poly3DCollection object at 0x7f3293d32e50> <matplotlib.text.Text object at 0x7f3293d79290> <matplotlib.text.Text object at 0x7f329643d050> <matplotlib.text.Text object at 0x7f3293d3a450>