我当时正在做一个项目,这个项目需要我获得一个物体的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会有帮助吗)?
提前感谢
发布于 2020-07-04 01:19:03
以下代码将地块另存为.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()发布于 2020-07-04 01:21:16
如果您只是希望将绘图作为图像文件下载,我建议添加以下代码行:
fig.savefig('some_name.png', format='png', dpi=100, bbox_inches='tight')如果您正在寻找交互式3D绘图,我建议您安装并使用plotly库。
下面是一个示例代码,它输出一个类似于您上面描述的3D绘图:
import plotly.graph_objects as go
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]
fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z,
mode='markers',
marker=dict(size=2))])
fig.show()
fig.write_html("some_plot.html")绘图被保存为html文件,可以使用浏览器查看该文件并与其交互。
https://stackoverflow.com/questions/62719756
复制相似问题