从可绘制的3D图形中获取相机位置 [英] Grab camera position from plotly 3d graph

查看:155
本文介绍了从可绘制的3D图形中获取相机位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制3D图形,并想要调整相机位置.对我而言,最好的方法是使用查看器,根据需要缩放和旋转场景,然后将相机位置作为JSON并将其放入我的脚本中,以生成图片以默认达到相同位置.

I'm drawing plotly 3D graph and want to adjust camera position. The best way to do it for me is to use viewer, zoom and rotate scene as needed, then grab camera position as JSON and put it into my script that generate the picture to achieve the same position by default.

根据此推文,它应该可以运行,但是不能.

According to this tweet, it should be working, but it doesn't.

我的代码是:

from plotly.graph_objs import Scatter3d, Layout, Scene
from plotly.offline import iplot
import plotly
from numpy import sin, cos, linspace, pi, zeros_like

plotly.offline.init_notebook_mode()

t = linspace(0, 4*pi)

trace1 = Scatter3d(
    x = t,
    y = cos(t),
    z = sin(t),
    mode = 'lines'
)

layout = Layout(
                width = 600, 
                height = 600, 
                scene = Scene(
                    xaxis = {'title': 't'},
                    yaxis = {'title': 'x'},
                    zaxis = {'title': 'y'},
                    camera =
                      {'eye':{'x':0,'y':1,'z':0}, 
                       'up': {'x':0,'y':0,'z':1}, 
                       'center': {'x':0,'y':0,'z':0}}
                )
)
iplot(dict(data=[trace1], layout=layout))

然后我得到一张照片:

点击在云中保存并编辑",切换到绘图界面,调整摄像头位置,然后单击查看JSON",仍然获得我在布局"中指定的默认摄像头位置.

click 'save and edit in the cloud', switch to plotly interface, adjust camera position and click View JSON and still get the default camera position as I specified in Layout.

推荐答案

这是预期的行为.

plotly.js不会在将摄像机位置发送到plot.ly云之前保存摄像机位置.您需要将图形保存在 plot.ly/plot 的绘图工作区中,以便更新其属性.

plotly.js doesn't save the camera position before sending it to the plot.ly cloud. You'll need to save your graph in the plotly workspace at plot.ly/plot in order to update its camera attribute.

这篇关于从可绘制的3D图形中获取相机位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆