共計 731 個字符,預(yù)計需要花費 2 分鐘才能閱讀完成。
要使用 Python 畫三維立體圖,可以使用 matplotlib 庫中的 mpl_toolkits.mplot3d 模塊。下面是一個簡單的示例代碼,用于繪制一個簡單的三維立方體圖形:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# 繪制立方體的頂點
vertices = [[0, 0, 0],
[1, 0, 0],
[1, 1, 0],
[0, 1, 0],
[0, 0, 1],
[1, 0, 1],
[1, 1, 1],
[0, 1, 1]
]
# 繪制立方體的邊
edges = [[0, 1],
[1, 2],
[2, 3],
[3, 0],
[4, 5],
[5, 6],
[6, 7],
[7, 4],
[0, 4],
[1, 5],
[2, 6],
[3, 7]
]
for edge in edges:
ax.plot([vertices[edge[0]][0], vertices[edge[1]][0]],
[vertices[edge[0]][1], vertices[edge[1]][1]],
[vertices[edge[0]][2], vertices[edge[1]][2]], color='b')
# 設(shè)置坐標(biāo)軸標(biāo)簽
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
運行以上代碼,將會繪制一個簡單的三維立方體圖形。可以根據(jù)需要修改頂點和邊的坐標(biāo)來繪制不同形狀的三維圖形。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完