python - 如何在 plotly 中更新来自多个跟踪的数据?
问题描述
我有一组图表,我想在同一个图中绘制。每个图对应一个go.Scatter
对象。在 plotly 中,我正在尝试使用该go.Layout.updatemenus
参数来构建一个下拉菜单,该菜单允许选择我想要绘制的图形对。
当我选择一个新的对时,我必须更新两个go.Scatter
对象中的数据,并且还要更新对象中的数据go.Layout
。我尝试执行以下操作,但没有成功。
trace1 = go.Scatter(
x = x_data1,
y = y_data1,
name = name1,
mode = 'markers',
marker = dict(
size = 2
)
)
trace2 = go.Scatter(
x = x_data1,
y = y_data1,
name = name2,
mode = 'lines',
line = dict(
color = 'Red',
width = 3
)
)
buttons_list = []
for key in dictio.keys():
buttons_list.append(dict(
label=key,
method='update',
args=[{"x": dictio[key].xdata1,
"y": dictio[key].ydata1,
"name": key},
{"x":dictio[key].xdata2,
"y":dictio[key].ydata2},
{"annotations": get_annotations(key)}
]
)
)
updatemenus = list([
dict(
active=0,
buttons=buttons_list,
direction='down',
x = 0.05,
xanchor='left',
y = 1,
yanchor='top'
)
])
layout = go.Layout(
updatemenus = updatemenus,
annotations = annotations,
)
fig = go.Figure(data=data, layout=layout)
plot(fig, auto_open=True)
解决方案
推荐阅读
- ssl - 在 Lumen 5.6 中强制 SSL 路由
- python-3.x - 如何根据另一个 csv 文件替换文件 csv 的值?
- r - eval(family$initialize) 中的错误:y 值必须为 0 <= y <= 1
- javascript - 如何将“this”对象放入回调函数?
- r - 计算列表中元素的平均值
- scala - Scala:将配置数据作为全局对象
- scheme - 不是给出批处理模式的命令,而是给出 .scm 文件路径?
- python - 从文本文件中的输入中按字母查找多个单词
- go - 如何将 row.Scan() int32 放入 Golang gRPC protobuf Enum 字段?
- linux-kernel - 如何通过从用户空间提供文件指针来从内核空间接收文件指针