Here is an example code using plotly.tools
to make subplots, then I used the prop legendgroup
to group together the traces.
# 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
Hope it solves your issue