[英]How to add names to dropdown menu in Plotly
我不太擅长 python,对 plotly 也很陌生。我在 Plotly 图中的下拉菜单旁边添加标签(名称)时遇到了问题。 我设法构建了一个交互式表格,您可以在其中按列过滤数据,并在 plotly 网站上进行快速研究。 但是,我找不到在这些下拉菜单旁边添加标签的方法。
plotly 网站上有一个示例代码,但我无法将其应用到我的图中。 你能帮我解决这个挑战吗? 这是我创建这个交互式图形的表格,也是我开发它的代码。
编辑:我也添加了这个数字。
fig7 = go.Figure(go.Table(header={'values': sample_targets.columns},
cells={'values': sample_targets.T.values,'align':'left'}))
fig7.update_layout(
updatemenus=[{'y': 1 - i / 5, 'buttons': [{'label': c,
'method': 'restyle',
'args': [{'cells': {'values': (sample_targets.T.values if c
== 'All'
else sample_targets.loc[sample_targets[menu].eq(c)].T.values)}}]}
for c in ['All']
+ sample_targets[menu].unique().tolist()]} for (i,
menu) in enumerate(['Country', 'Company','sentence'])],
legend=dict(title_font_family='Times New Roman'),
font=dict(size=12),
autosize=False,
width=1200,
height=900,
template='simple_white'
)
fig7.show()
如果你能帮助我,我将不胜感激。 提前致谢。
我发现我已经完成了这项工作,但错过了关于定位标签(按钮)的细微差别。 当我在注释中使用 position 参数时,我设法正确添加了名称。
fig7.update_layout(annotations=[
dict(text="Country", x=-0.2, xref="paper", y=1.025, yref="paper",
align="left", showarrow=False),
dict(text="Company", x=-0.21, xref="paper", y=0.83,align="left",
yref="paper", showarrow=False),
dict(text="Target sentence", x=-0.215, xref="paper", y=0.615,
yref="paper",align="left",
showarrow=False)
])
fig7.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.