首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止使用Plotly-python绘图后重置摄像机

防止使用Plotly-python绘图后重置摄像机
EN

Stack Overflow用户
提问于 2019-10-12 00:34:53
回答 1查看 1.4K关注 0票数 7

我正在尝试使用dash和plotly绘制3d箭嘴或圆锥体的一些数据,我想通过间隔输入定期更新图形!

因此,我设法使图形具有动画效果,但问题是,每次更新后,相机角度和变焦都会不断重置。我有以下代码:

代码语言:javascript
复制
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from dash.dependencies import Output, Input
import pickle


#reading initial data
with open("shared.pkl", "rb") as f:
    quivDic = pickle.load(f)


quiver_3d = go.Cone(x = quivDic["X"], y = quivDic["Y"], z = quivDic["Z"],
                    u = quivDic["U"], v = quivDic["V"], w = quivDic["W"],
                    colorscale = 'Blues', name = "testScatter")
data = [quiver_3d]
layout = dict(title ="Test Quiver", showlegend=False, aspectratio=dict(x=1, y=1, z=0.8),
                             camera_eye=dict(x=1.2, y=1.2, z=0.6))

fig = dict(data=data, layout=layout)


app = dash.Dash()
app.layout = html.Div([
    html.Div(html.H4("TEST CONE")),
    html.Div(dcc.Graph(id = "testCone", figure=fig)),
    dcc.Interval(
            id='graph-update',
            interval=1000,
            n_intervals = 0
        ),
])

@app.callback(Output('testCone', 'figure'),
        [Input('graph-update', 'n_intervals')])
def refresh(n):
    #reading new data
    with open("shared.pkl", "rb") as f:
        quivDic = pickle.load(f)

    quiver_3d.x = quivDic["X"]
    quiver_3d.y = quivDic["Y"]
    quiver_3d.z = quivDic["Z"]
    quiver_3d.u = quivDic["U"]
    quiver_3d.v = quivDic["V"]
    quiver_3d.w = quivDic["W"]

    data = [quiver_3d]
    #creating new figure
    fig = dict(data=data)

    return fig




app.run_server(debug=True)

有谁知道如何避免这个问题吗?理想情况下,我希望在不重绘整个框架的情况下更新数据,就像matplotlib中的"set_data“一样。否则,有没有办法跟踪最新的摄像头角度并通过回调更新布局?感谢^^

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-12 03:59:03

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58345327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档