![](/img/trans.png)
[英]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.