# Graphs sharing same legend

**URL:** https://community.plotly.com/t/graphs-sharing-same-legend/12476
**Category:** Dash Python
**Created:** [August 7, 2018, 6:16am UTC](https://community.plotly.com/t/graphs-sharing-same-legend/12476 "2018-08-07T06:16:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![majabaaaa](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@majabaaaa](https://community.plotly.com/u/majabaaaa)
#### Post date: [August 7, 2018, 6:16am UTC](https://community.plotly.com/t/graphs-sharing-same-legend/12476/1 "2018-08-07T06:16:40Z")

</div>

Hello,  
I have three different graphs each with an unique id and callbacks with the same input, that have the same legend entries. Is there a way for an easier overview, that I have one legend for all three figures and if I select or deselect an entry that all three figures are updated?  
Also is there a way for showing the plot title only once for all three graph, because I have the same title for all three?

Thank you!

---

<div class="post-metadata">

### Author: ![Bachibouzouk](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bachibouzouk/32/3594_2.png) [@Bachibouzouk](https://community.plotly.com/u/Bachibouzouk)
#### Post date: [August 7, 2018, 8:57am UTC](https://community.plotly.com/t/graphs-sharing-same-legend/12476/2 "2018-08-07T08:57:57Z")

</div>

Hello @majabaaaa,

could you provide an example of your graphs code and/or a printscreen of how your three graphs look like?

This would help us helping you 🙂

Thanks

---

<div class="post-metadata">

### Author: ![majabaaaa](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@majabaaaa](https://community.plotly.com/u/majabaaaa)
#### Post date: [August 7, 2018, 9:24am UTC](https://community.plotly.com/t/graphs-sharing-same-legend/12476/3 "2018-08-07T09:24:26Z")

</div>

![secondp](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/7/75eb82d206f39981e1f3d768a64aa4ef782eb5c4.png) ![firstp](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/3/30489db22e94be9057bb492ecbb8ce27cd6d0ece.png)

Like in the images I have different plots with the same data source, so the legend that is created by both of them is from the same source.  
The last image is what I want to achieve. To have the plots use the same legend to show hide entries in both plots

 ![ideal](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/6/648da0cc999e9cebdb9bcaca35896fdd5b57a993.png)

---

<div class="post-metadata">

### Author: ![Bachibouzouk](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bachibouzouk/32/3594_2.png) [@Bachibouzouk](https://community.plotly.com/u/Bachibouzouk)
#### Post date: [August 7, 2018, 11:10am UTC](https://community.plotly.com/t/graphs-sharing-same-legend/12476/4 "2018-08-07T11:10:07Z")

</div>

Here is an example code using `plotly.tools` to make subplots, then I used the prop `legendgroup` to group together the traces.

```auto
# In[]:
# Import required libraries
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output, State, Event

import plotly.graph_objs as go
from plotly import tools

# Define the app
app = dash.Dash('')
server = app.server
app.config.suppress_callback_exceptions = False
app.scripts.config.serve_locally = True

fig = tools.make_subplots(
    rows=1, cols=2, print_grid=False,
    subplot_titles=('Graph1', 'Graph2'))

fig.append_trace(
    go.Bar(
        x=[1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
           2003,
           2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
           2012],
        y=[219, 146, 112, 127, 124, 180, 236, 207, 236, 263,
           350, 430, 474, 526, 488, 537, 500, 439],
        name='Data_trace1',
        legendgroup='group1'
    ),
    1,
    1
)
fig.append_trace(
    go.Bar(
        x=[1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
           2003,
           2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
           2012],
        y=[16, 13, 10, 11, 28, 37, 43, 55, 56, 88, 105, 156,
           270,
           299, 340, 403, 549, 499],
        name='Data_trace2',
        legendgroup='group2'
    ),
    1,
    1
)

fig.append_trace(
    go.Bar(
        x=[1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
           2003,
           2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
           2012],
        y=[219, 146, 112, 127, 124, 180, 236, 207, 236, 263,
           350, 430, 474, 526, 488, 537, 500, 439],
        name='',
        legendgroup='group1'
    ),
    1,
    2
)
fig.append_trace(
    go.Bar(
        x=[1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
           2003,
           2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
           2012],
        y=[16, 13, 10, 11, 28, 37, 43, 55, 56, 88, 105, 156,
           270,
           299, 340, 403, 549, 499],
        name='',
        legendgroup='group2'
    ),
    1,
    2
)

root_layout = html.Div(
    [
        dcc.Graph(
            figure=fig,
            id='my-graph'
        )
    ]
)

app.layout = root_layout

# In[]:
# Main
if __name__ == ' __main__':
    app.run_server(debug=False)

```

Here is a visual

 ![2018-08-07_graph_legend](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/f/f225c2d6b82e2da83b6964bf5fc7fb61dcf0da13.png) ![2018-08-07_graph_legend2](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/7/778b54d6059bad7d691343103de14c6b696f8c80.png)

Hope it solves your issue 🙂

---

<div class="post-metadata">

### Author: ![Bachibouzouk](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bachibouzouk/32/3594_2.png) [@Bachibouzouk](https://community.plotly.com/u/Bachibouzouk)
#### Post date: [August 7, 2018, 11:53am UTC](https://community.plotly.com/t/graphs-sharing-same-legend/12476/5 "2018-08-07T11:53:27Z")

</div>

> [@majabaaaa](#):
>
> Also is there a way for showing the plot title only once for all three graph, because I have the same title for all three?

I forgot to address this point in my previous reply, simply add the line

```auto
fig.layout.update(title='your_title_here', showlegend=True)

```
