Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly subplots with individual legends

I would like to display multiple subplots in one plot. Since the number of lines drawn are many, I would like to display the legend per subplot. The legend is currently displayed for all subplots (making reading the charts very cumbersome).


Unfortunately, plotly can only support one legend per graph at the moment.

I’d recommend using annotations instead.

1 Like

I have the same problem. Without the control on legends, large subplots become very complex to read, and the business users are confused with flying/ungrouped/wrongly-positioned legends :frowning: Control on legends will help in making the plots very intuitive and simple. Hope you will add this feature asap…

Here is my github issue for the same-

Is there any new update on this issue?.


I have the same problem. Any update on this issue?

I used two side by side Div elements to emulate Plotly subplot . Doing this way, we have independent legends. However, if we want to share an axis, we should do it manually:

app.layout = html.Div(children=[
        html.Div(['YOUR FIRST GRAPH OBJECT'],
                 style = {'float':'left', 'width':'49%'}) ,
        html.Div(['YOUR SECOND GRAPH OBJECT'],
                 style = {'float':'right', 'width':'49%'})   

Is this possible now?

1 Like

So how do you zoom-in synchronously then?

Hello :slight_smile:
I have the same problem, and the same question then :sweat_smile: : “How can you manually set shared axis?”

The otherwise good support for common zooming and panning of subplots is severely marred by the inability to display legends per subplot. I would be grateful if users here could comment on how they are getting around this.

Has anyone managed to get separate legends to show on each subplot?
Has anyone implemented common zooming and spanning across separate plots which are not subplots of a common figure?

Any suggestions of a better python interactive plotting library that can achieve this?

1 Like

Same issue as others in the group: The inability to display a legend for each subplot is unfortunate from a business perspective. For example, when displaying subplots with same colors the legend devolves and is difficult or impossible to interpret. One might simply alter the colors, but there are easily imagined cases where matching colors across subplots would be ideal to illustrate similar cohorts. Hope that this issue is addressed in a future release.

1 Like

Did you find a workaround? I am also stuck due to this missing feature :frowning:

I have 6 subplots, their legends/colorbar looks aweful by default.
The documentation shows little info on how to use the api.

Can anyone help?

Here is a workaround. It allows you to disable a legend for a subplot or to make plots share the same legend entry by using a combination of legendgroup and showlegend = False.

Thank NeStack, but as far as I can tell this workaround only disables certain traces from the legend.
There is still no way, as far as I can tell, to use legendgroups and retain the ability to toggle traces on and off independently (the entire legend group is toggled instead). Then there is the fact that legendgroup spacing needs to be handcoded to match subplot positioning.

So users are left to choose between being able to toggle traces (very useful) or being able to display readable legends (essential). You cannot do both.

A thorough solution would include separate legends per subplot.

Admittedly I’d settle for an option to toggle individually rather than by grouplegend. Perhaps that can be an initial fix.

I believe I have the same issue already reported in this thread, if so, this is just a +1.

  1. I have a subplot with 2 rows and 1 column
  2. Both plots share x axes, so I can zoom in and out both at the same time
  3. Some legends are grouped, other are single legends
  4. There are no shared legends between subplots, all legends belong either to row 1 or 2
  5. I need the ability to toggle visibility of each data + legend individually

Is there a way to display the legend next to each row?

In the example below, orange marked legends belong to the bottom plot.

The way it is presented is counterintuitive :frowning:

This post has a lot of views, so for readers interested in subplots legends: we have an open issue in plotly.js for this feature, to which you can subscribe for updates. However, it represents a substantial amount of work. If anyone here works for an organization that has a software budget, we do accept sponsorship for features, which would enable us to build this feature faster. See for more details!