0

how to add button like this below to toggle data from all traces on the scatter? toggle buttons

Thanks, Paulina

3
  • Just to confirm, did you know that you can hide the graph by clicking on the legend? Commented Jun 18, 2022 at 13:50
  • @r-beginners Yes, I know. Is this related? Commented Jun 18, 2022 at 20:26
  • I mistakenly thought the function of that button was to show or hide the graph. Commented Jun 19, 2022 at 7:37

1 Answer 1

1

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.