Search code examples
pythonpython-3.xplotly

Unmark all labels when show plotly figure


I have this code:

df = pd.DataFrame(np.random.rand(5, 6))
fig = px.bar(df)
fig.show()

which show this output: enter image description here

I would like the starting output unmark all the variables (or to add a button that unmark them), so this will be the starting output: enter image description here


Solution

  • Straight forward use of update_traces()

    df = pd.DataFrame(np.random.rand(5, 6))
    fig = px.bar(df).update_traces(visible="legendonly")
    fig.show()