import matplotlib.pyplot as plt
import numpy as np
a = 1 # 边长
h = 2 # 高度
theta = np.linspace(0, 2*np.pi, 7)
x_base = a * np.cos(theta)
y_base = a * np.sin(theta)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# 绘制底面和顶面
ax.plot(x_base, y_base, 0, 'b')
ax.plot(x_base, y_base, h, 'r')
# 绘制侧面
for i in range(6):
ax.plot([x_base[i], x_base[i]], [y_base[i], y_base[i]], [0, h], 'g')
plt.show()