✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Hover Data on Go.Scatter and or shared Legends with plotly express

Hi work with plotly Go and plotly express.

I need legendgroups for my charts to update all similar if i click an value in the legend. So my current knowledge says that i cant use plotly express (correct me if I am wrong). So I have to use plotly GO, but with go there is no hoverdata? Sad that both together have all what I need.

I have an issue. I need Hoverdata on for e.g., but this doesnt work. I can use hoverdata with plotly express, but plotly express doesnt accept Legendgroup

*How to set Hover Data here?*
figw.append_trace(
     go.Scatter(
        x=data["Time"],
        y=data["Sun"],
        name=str(data["Date"].unique())[2:-2],
        legendgroup='group'+str(i),
        showlegend=False,
        marker=dict(color=d[j]),
        hovertext=[data["Time"],data["Sun"],data["Temperature"],data["Consumption"],data["Pressure"]],
 
*How to set Legendgroup here?*
fig1bar = px.bar(dfbar1, x='Date',
                 y='Consumption',
                 hover_data=["Date", "Consumption"],
                 labels={'Consumption':'Energy'},
                 color='Date',
                 text="Date",
                 title = "Title",
                 
                 
                 )

Hi @0000,

  1. for adding hover data to a go trace you can use customdata and a hovertemplate, as described in https://plot.ly/python/hover-text-and-formatting/#adding-other-data-to-the-hover-with-customdata-and-a-hovertemplate
  2. you can update a px figure using fig.update_traces, for example
fig.update_traces(legendgroup='group')

(update_traces takes a selector argument if you need to select only some traces)

I would recommend the 2nd method.

2 Likes

hi, thank you very much… so its also possible to create legendgroups without subplots? so sharing legends and select them parallel over multiple figures?

My problem is i have grouped data so if i use plotly express and i set legendgroup all traces of this chart appear or are gone…

I’m not sure I understand. You don’t need subplots to use legendgroup, see for example https://plot.ly/python/legend/#grouped-legend. Maybe you could share a standalone code to explain what you would like to do?

1 Like

yes subplots working, thanks

Hi, I get the same issue! It seems you found the solution by using go and subplot. Did you also find a solution with plotly express?
:wave:t4: