Hiding two graphs when legend clicked on

Example with lines+markers:

import numpy as np
import pandas as pd
import plotly.express as px

data = pd.DataFrame(np.random.rand(100, 2), columns=["A", "B"]).reset_index()

fig = px.line(
    data,
    x="index",
    y=["A", "B"]
)
fig.update_traces(
    mode="lines+markers",
    marker_color=data["index"].between(25,75).map({True: "magenta", False: "green"})
)
fig.show()

1 Like