Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬 Register for the Oct 27 webinar.

Can't seem to get legendgrouptitle to work

I am trying to implement the new 5.1.0 plotly legendgrouptitle but cannot seem to get it to work. I am doing something similar to this:

fig = make_subplots(
    rows=4,
    cols=1,
    shared_xaxes=True,
    specs=[[{"secondary_y": True}], [{"secondary_y": True}], [{"secondary_y": True}], [{"secondary_y": True}]]
)
legend_groups = [1,2,3,4]
for legend_group in legend_groups:
    fig.add_trace(
        go.Scatter(
            x=df['<some timestamp data>'],
            y=df['<some data>']
            name='<some name>',
            legendgroup=legend_group,
            legendgrouptitle=dict(text=legend_group)
        ),
        secondary_y=False,
        row=legend_group,
        col=1
    )
    fig.add_trace(
        go.Bar(
            x=df['<some timestamp data>'],
            y=df['<some data>']
            name='<some name>',
            legendgroup=legend_group,
        ),
        secondary_y=True,
        row=legend_group,
        col=1
    )

I think possibly it could be because I am using a subplot as my figure or also because I am using secondary_y axes but I have no real idea. My confusion stems from the fact that the legend groups work correctly because the traces are grouped accordingly, but their titles fail to appear.

Have you been able to solve your problem? I’m dealing with a very similar issue using plotly (5.1.0) and dash! I’ve noticed that the legend title appears when I return the chart as an image in JupyterLab, but when I run the dash app, it vanishes.
Legends in Jupyter:

Legends in Dash App:

In both situations I’m using the same code to add the traces and to update the layout, so I’m very confused about about why it does not work in my dash…

No I still have not been able to solve it. I did not even try to run my code in jupyter, so that is very interesting that it works in jupyter but not dash. I had also been running mine in dash when it was not displaying correctly. Unfortunately I wound up giving up because I could not find where the error was. Hopefully it is a simple fix that is resolved in a patch :smiley:

Has anyone figured this out? I’m having the exact same issue in plotly==5.1.0!!! IT is so frustrating

@skunkworks and @pensixnine
I ran the example in this post: Trying to get Legend Titles to work - #10 by AnnMarieW

and it works if you upgrade to Dash 1.21.0 and use Plotly 5.1.0

1 Like

I’m still encountering the error in a scatter plot after upgrading.

If you can provide a minimal example like this Trying to get Legend Titles to work - #9 by cinthia, I could try to run it and I might be able to help.

Hello,

Using dash (2.0.0) and plotly (5.3.1) same issue happens.
Legendgroup text is not displayed.

Any hint ?

Hi!

My issue was solved by updating dash from 1.20.0 to 1.21.0. Since you are using the latest version of dash, it’s probably a different problem. Can you share some example like here?

Hello !

Thanks Cinthia for the hint… I tried your examples and they work just fine…

It seems the issue is related to the way legendgrouptitle text is passed when using a dict to build the traces instead of using add_trace function.

This does NOT work:
trace = dict(…, legendgrouptitle_text=“group_name 2”, legendgroup = “g2”, …)

however, this works:
trace = dict(…, legendgrouptitle=dict(text=“group_name 2”), legendgroup = “g2”, …)

Best regards,
Arnaud