Hi,
I am trying to exchange the data in a scatter plot via a button. I would like to replace the data, not hide it (visible = False
). I am following the examples here: https://plotly.com/python/custom-buttons/#update-button
This is my code that I think should work given the examples in the link above. However, the data displayed does not change. How can I make this work?
import pandas as pd
import plotly.graph_objects as go
df = pd.DataFrame(dict(a=[1, 2, 3], b=[1, 2, 3], c=[4, 8, 6]))
fig = go.Figure()
fig.add_trace(go.Scatter(x=df.a, y=df.b, mode="markers"))
fig.update_layout(
updatemenus=[
dict(
type="buttons",
direction="right",
x=0.6,
y=1.2,
showactive=True,
buttons=list(
[
dict(label="B", method="restyle", args=["y", df["b"]]),
dict(label="C", method="restyle", args=["y", df["c"]]),
]
),
)
]
)
fig.show()
I also tried data.y, scatter.y, scatter.data.y etc. nothing helps.
Thanks a lot!
Edit: I works with args=["y", [df.c]]