Editing subplot layouts (Adding shapes, drop-down menus)

For those who think the tutorials referenced above do not demonstrate how to draw shapes on subplots here is an example that worked for me:

import plotly.offline as ofl
import plotly.plotly as py
import plotly.tools as tls
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[10, 20, 30],
    y=[40, 50, 60]
)
trace2 = go.Scatter(
    x=[20, 30, 40],
    y=[50, 60, 70]
)
trace3 = go.Scatter(
    x=[30, 40, 50],
    y=[60, 70, 80]
)
trace4 = go.Scatter(
    x=[40, 50, 60],
    y=[70, 80, 90]
)
shapes = [
    {'type': 'line', 'x0': 25, 'y0': 100, 'x1': 35, 'y1': 100, 'xref': 'x1', 'yref': 'y1'},
    {'type': 'line', 'x0': 25, 'y0': 200, 'x1': 35, 'y1': 200, 'xref': 'x2', 'yref': 'y2'},
    {'type': 'line', 'x0': 25, 'y0': 300, 'x1': 35, 'y1': 300, 'xref': 'x3', 'yref': 'y3'},
    {'type': 'line', 'x0': 25, 'y0': 400, 'x1': 35, 'y1': 400, 'xref': 'x4', 'yref': 'y4'}
]

fig = tls.make_subplots(rows=2, cols=2)
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 2)
fig.append_trace(trace3, 2, 1)
fig.append_trace(trace4, 2, 2)

fig['layout'].update(shapes=shapes)

ofl.iplot(fig, filename='multiple-subplots')
5 Likes