python - 在 plotly 中更新绘图上的 xy 数据
问题描述
我正在通过使用以下代码生成 JSON 来使用 plotly 构建网页:
def get_json_data() -> str:
df1 = pd.read_csv()
fig = make_subplots(
rows=2, cols=1,
shared_xaxes=True,
vertical_spacing=0.03,
specs=[[{"type": "xy"}],
[{"type": "table"}]],
subplot_titles=["Close price history", "Close price forecast"],
);
fig1 = px.line(df1, x=df1.index, y='field']);
fig.add_trace(fig1['data'][0], row=1, col=1);
fig.add_table(
header=dict(values=["ColumnA"]),
cells=dict(values=[[100]),
domain=dict(x=[0, 1], y=[0, 0.3]),
row=2, col=1
);
fig.update_layout(
autosize=False,
height=1300,
width=1500);
graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder, indent=4);
return graphJSON;
结果用于呈现具有以下内容的 html 文件div
:
<div id='chart' class='chart'”></div>
和一个脚本,如
<script type='text/javascript'>
var graphs = {{graphJSON | safe}};
Plotly.plot('chart',graphs,{});
</script>
当新数据到来时,我想更新绘图的 x 和 y 数据,而不是整个页面。例如,如果用户放大了,我不想刷新一切让他/她再次放大,但我只想添加新数据。有可能用情节来做到这一点吗?
解决方案
推荐阅读
- php - 在 Laravel 中通过 Passport 服务注册用户的问题
- r - 错误:美学必须是长度 1 或与数据 (1) 相同:x
- heroku - 来自子目录中 create-react-app 的代理 $PORT 值
- reactjs - Onclick 函数产生“函数语句需要函数名”错误
- javascript - 在 ExtJs 5.0 Grid 中使用 contextMenu 复制特定的单元格值
- itext - 我如何知道何时添加新页面?
- c++ - 在 c++11 中的向量中的第 1000 个元素之后不能 push_back()
- c# - 在 .Net Core 3.1 中找不到“System.Windows.Clipboard”
- scrapy - Scrapy - 每个进程/作业的项目管道类的新实例?
- python - Tkinter Icon Exe File:如果我将文件发送给某人,为什么它不起作用?