Subplot with multiple y axis

Thanks!
I still have problems with it - I rewrote the code with using your answer in the link you posted.
The problem is that when I plot the graph one of the sublots is empty. While when I press the “Export plot.ly” button I see that subplot correctly:
auto_open plot:


export to plot.ly:

Do you have idea what is the cause of this?

from plotly import tools
import plotly.graph_objs as go
from plotly.offline import plot

x = [0, 2, 3, 4, 5, 6, 7, 9]
y1 = [0, 2, 3, 4, 5, 6, 7, 9]
y2 = [10, 14, 16, 18, 20, 22, 24, 28]
y3 = [10, 8, 7, 6, 5, 4, 3, 1]
y4 = [25, 21, 19, 17, 15, 13, 11, 7]
y5 = [25, 21, 19, 17, 15, 13, 11, 7]
y6 = [25, 21, 19, 17, 15, 13, 11, 7]
title_list = [‘a’, ‘b’, ‘c’]

fig = tools.make_subplots(rows=2, cols=2, print_grid=True, horizontal_spacing=0.18, subplot_titles=title_list)

trace1 = go.Scatter(x=x, y=y1, mode=‘lines’, name=‘y1’, showlegend=False)

trace2 = go.Scatter(x=x, y=y2, mode=‘lines’, name=‘y2’, showlegend=False)

trace3 = go.Scatter(x=x, y=y1, mode=‘lines’, name=‘y3’, showlegend=False)

trace4 = go.Scatter(x=x, y=y3, mode=‘lines’, name=‘y3’, showlegend=False)

trace5 = go.Scatter(x=x, y=y5, mode=‘lines’, name=‘y4’, showlegend=False)

trace6 = go.Scatter(x=x, y=y4, mode=‘lines’, name=‘y4’, showlegend=False)

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace4, 1, 1)
fig.append_trace(trace2, 1, 2)
fig.append_trace(trace5, 1, 2)
fig.append_trace(trace3, 2, 1)
fig.append_trace(trace6, 2, 1)

fig[‘data’][1].update(yaxis=‘y4’)
fig[‘data’][3].update(yaxis=‘y5’)
fig[‘data’][5].update(yaxis=‘y6’)

fig[‘layout’].update(autosize=False, width=800, height=500, showlegend=False, hovermode=‘x’)

fig[‘layout’][‘yaxis1’].update(range=[0, 9], showgrid=True, title=‘y1’)

fig[‘layout’][‘yaxis2’].update(range=[10, 28], showgrid=True, title=‘y2’)

fig[‘layout’][‘yaxis3’].update(range=[0, 9], showgrid=True, title=‘y3’)

fig[‘layout’][‘yaxis4’] = dict(range=[1, 10], overlaying=‘y1’, anchor=‘x1’, side=‘right’, showgrid=False, title=‘y4’)

fig[‘layout’][‘yaxis5’] = dict(range=[7, 28], overlaying=‘y2’, anchor=‘x2’, side=‘right’, showgrid=False, title=‘y5’)

fig[‘layout’][‘yaxis6’] = dict(range=[7, 25], overlaying=‘y3’, anchor=‘x3’, side=‘right’, showgrid=False, title=‘y6’)

plot(fig, filename=’/home/…/test.html’, auto_open=True)

1 Like