简体   繁体   English

如何在绘图图表中添加按钮以切换多条轨迹?

[英]How to add button to plotly chart to toggle multi traces?

how to add button like this below to toggle data from all traces on the scatter?如何添加像下面这样的按钮来切换散点图上所有迹线的数据? 切换按钮

Thanks, Paulina谢谢,宝琳娜

The hover text data comparison button on the menu bar does not appear to be visible at all times.菜单栏上的悬停文本数据比较按钮似乎并非始终可见。 I do not know why.我不知道为什么。 Adding the following code will make it appear.添加以下代码将使其出现。 This tips was confirmed from here .这个提示从这里得到了证实。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM