[英]Plotly: How to toggle traces with a button similar to clicking them in legend?
[英]How to add button to plotly chart to toggle multi traces?
菜单栏上的悬停文本数据比较按钮似乎并非始终可见。 我不知道为什么。 添加以下代码将使其出现。 这个提示从这里得到了证实。
import plotly.graph_objects as go
# Create random data with numpy
import numpy as np
np.random.seed(1)
N = 100
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N) + 5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N) - 5
fig = go.Figure()
# Add traces
fig.add_trace(go.Scatter(x=random_x, y=random_y0,
mode='markers',
name='markers'))
fig.add_trace(go.Scatter(x=random_x, y=random_y1,
mode='lines+markers',
name='lines+markers'))
fig.add_trace(go.Scatter(x=random_x, y=random_y2,
mode='lines',
name='lines'))
fig.update_layout(modebar_add=[
"v1hovermode",
"toggleSpikelines",
])
fig
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.