我需要使用matplotlib绘制圆柱面。
我不明白为什么我的代码无效...
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()
答案 0 :(得分:0)
您需要生成二维曲面的坐标才能使用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()
产生