简体   繁体   中英

3D plot of cylindrical surface in Python

I need to plot a cylindrical surface using matplotlib.

I don't understand why my code isn't working...

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, 1)

x = 10 * np.cos(u)
y = 10 * np.sin(u)
z = 10
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')

plt.show()

You need to generate the coordinates of a two-dimensional surface to use ax.plot_surface :

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')

us = np.linspace(0, 2 * np.pi, 32)
zs = np.linspace(0, 10, 2)

us, zs = np.meshgrid(us, zs)

xs = 10 * np.cos(us)
ys = 10 * np.sin(us)
ax.plot_surface(xs, ys, zs, color='b')

plt.show()

which produces

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM