python - 如何在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 帮助)?
提前致谢
解决方案
以下代码将您的情节另存为.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()
推荐阅读
- php - Yii2 连接到另一台服务器上 Docker 实例内的 MYSQL 数据库
- export-to-csv - DBeaver 导出为 CSV
- c++ - 我们可以通过排序左起点来解决逐点覆盖问题吗
- android - 找不到 Gradle DSL 方法:'androidTestImplementation()'
- python - 如何修复 TypeError:'str' 对象在 Python 中不可调用
- javascript - 删除 VS 代码中的“\u200b”
- fabricjs - Fabricjs,选择手柄显示但在与其他形状一起选择之前不可点击
- python - 如何在 Python 中腌制一个函数?
- mysql - SQL:按列别名排序
- similarity - 实体有相似词的问题