Plotly_Express graph legends

Hi y’all

Before I started using plotly_express, I was using dcc.graph() like below (*). This way (because of the number of columns) using " ‘visible’: ‘legendonly’ " I effectively disabled all entries in the graph’s legend and the user could select only the ones they wanted.

(*) traces.append({‘x’: df_pv.index, ‘y’: df_pv[trace], ‘name’: trace, ‘mode’: ‘lines’,
‘visible’: ‘legendonly’})

Now I am using plotly_express and the code below (#) I can’t seem to find a way to do the same, tried Goggle but that didn’t help much.

(#) fig = px.scatter(df_pv, y=None, x=None, title=title, render_mode=‘lines’, height=470)
for col in df_pv.columns:
if col != cvs.CIRC_MY:
fig.add_scatter(y=df_pv[col], x=df_pv[cvs.CIRC_MY], name=col)

Any suggestions would be appreciated

Thanks
Stareagle

You should be able to just add visible='legendonly' to your add_scatter() call.

I should mention that in the example above, Plotly Express isn’t really doing anything for you (with x=None, y=None) so you can bypass PX in this case and just use fig = Figure(layout=dict(title="title", height=470)) :slight_smile: