你可以按照以下步骤编写一个绘制立方体的Python函数:
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.art3d as art3d
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
verts = [
[1, -1, -1],
[1, 1, -1],
[-1, 1, -1],
[-1, -1, -1],
[1, -1, 1],
[1, 1, 1],
[-1, -1, 1],
[-1, 1, 1]
]
faces = [
[0, 1, 2, 3],
[0, 4, 5, 1],
[1, 5, 6, 2],
[2, 6, 7, 3],
[3, 7, 4, 0],
[4, 7, 6, 5]
]
cube = art3d.Poly3DCollection([verts[face] for face in faces], alpha=0.25, facecolor='blue')
ax.add_collection3d(cube)
ax.set_xlabel('X')
ax.set_xlim3d(-2, 2)
ax.set_ylabel('Y')
ax.set_ylim3d