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

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

问题描述

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

根据

点击'save and edit in the cloud',切换到plotly界面,调整相机位置并点击View JSON,仍然得到我在Layout中指定的默认相机位置.

解决方案

这是预期的行为.

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

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.

My code is:

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))

Then I get a picture:

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.

解决方案

This is the intended behavior.

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.

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

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