首页 > 解决方案 > 如何在python中获取3D对象的坐标

问题描述

我正在做一个项目,该项目需要我获取对象的 3d 点。我已经有一些基本代码:

import matplotlib.pyplot as plt



fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x =[1,2,3,4,5,6,7,8,9,10]
y =[5,6,2,3,13,4,1,2,4,8]
z =[2,3,3,3,5,7,9,11,9,10]



ax.scatter(x, y, z, c='r', marker='o')

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

这基本上只是绘制随机点,然后用 matplotlib 打开它。有没有办法获取 3d 图像的文件并将其绘制在这样的东西上(我不知道如何解决这个问题,会使用 gcode 帮助)?

提前致谢

标签: pythonmatplotlib3d

解决方案


以下代码将您的情节另存为.png

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D



fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x =[1,2,3,4,5,6,7,8,9,10]
y =[5,6,2,3,13,4,1,2,4,8]
z =[2,3,3,3,5,7,9,11,9,10]



ax.scatter(x, y, z, c='r', marker='o')

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

#This saves the picture as a seperate file with the same file path as the .ipynb file
fig.savefig('foo.png', bbox_inches='tight')

plt.show()

推荐阅读