I can’t find out how to assign a secondary – right – y-axis to a subplot. This post on the Plotly forum - Subplots with two y axes - helped me on the way, but …
although the second y-axis (y3 AKA yaxis3) of the top subplot appears on the right (i.e. the fig[‘layout’][‘yaxis3’].update works),
the 2 traces (1 line, 1 marker) which should be linked to right y-axis y3, remain linked to the left y-axis y1.
Summary: both the top and the bottom subplot appear as expected, incl; the secondary y-axis of the top subplot. Only the 2 traces of the top subplot which should be linked to the secondary y-axis are still linked to the primary y-axis. How exactly should I assign ‘y3’ to yaxis3?
…
for iii in range(0,len(pc)):
…
trace[ii+iii+1] = go.Scatter(
x = col0,
y = col1,
name = hovertext[iii],
mode = ‘markers’,
xaxis = ‘x1’,
yaxis = ‘y1’ if iii!=9 else ‘y3’, # only the 10th trace should use the right y-axis y3 i/o y1
line = dict(width=0, color=colors[iii]),
marker = dict(
…
)
)
)
…
fig = tools.make_subplots(rows=2, cols=1, shared_xaxes=False, vertical_spacing = 0.5)
for n in range(0,iii+ii+2): # top subplot with 2 y axis’ - 10 th trace uses y3, the rest y1
** fig.append_trace(trace[n], 1, 1)**
fig.append_trace(trace[iii+ii+2], 2, 1) # simple x2 y2 subplot on the botttom
fig.append_trace(trace[iii+ii+3], 2, 1)
fig[‘layout’][‘xaxis1’].update(
title=’% Load’,
domain=[0, 1],
range=[0, 110],
…
)
fig[‘layout’][‘yaxis1’].update(
title=‘°C bar mm g/kWh engine rpm’,
domain=[0.15, 1],
range=[-1, 600],
…
)
fig[‘layout’][‘yaxis3’].update(
** anchor=‘x1’, **
** overlaying=‘y1’, **
** side=‘right’,**
title=‘T/C rpm’,
domain=[0.15, 1],
range=[14000, 18500],
…
)
fig['layout']['xaxis2'].update( # bottom subplot
title='UTC timestamp',
domain=[0, 1],
ticklen=0.25,
)
fig['layout']['yaxis2'].update(
title='% load',
domain=[0, 0.1],
range=[-10, 110],
...
)
fig['layout'].update(
...
)
plotly.offline.plot(fig, filename=...