Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Linking Plotly Annotations with Multiple Traces

Hello all,

I’m currently working with the latest version of plotly in Python. I’ve run into an issue that I’m hoping there is a workaround for. So basically what I have are line plots where for each line there is a portion that is solid and a later portion that is dashed. I understand that creating that amounts to basically creating separate traces for each portion, and I have that part implemented. In an ideal setting I would be able to click on an item of my legend that could then hide both the solid and traced line plots at the same time. My understanding though is that this isn’t possible, and that the legend entries are strictly tied to individual traces (i.e. you can’t have a legend entry linked to multiple traces). With that in mind I’m wondering if there may be a workaround in terms of annotations that could accomplish this? Specifically I’m thinking of a scenario where I’ve created my own custom “legend” comprised of annotations with markers which when clicked can hide multiple traces at a time. So in my scenario a “legend” entry could be clicked to simultaneously hide both the solid and dashed traces of a line at the same time. Before I go spinning my wheels too much trying to figure this out on my own I thought I’d throw this question out there. If anyone has suggestions on how to do this (and really awesome if there were code snippets as well) that would be great!

1 Like

Hi, I’m new to plotly but did you know about legendgroup param? See here https://plotly.com/python/legend/ worked pretty well for me