@new_learner
The side is assigned as expected, but with your code you cannot realise that itβs OK.
your lines:
fig.layout['yaxis']['side'] = 'left'
fig.layout['yaxis2']['side'] = 'right'
are un-necessary because, by default yaxis is at left, while the secondary yaxis2 at right.
I removed your lines that are not relevant to illustrate that yaxes are assigned correctly. Here is the default case (I set yaxes range to be more convincing):
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
fig = make_subplots(
rows=3, cols=4, shared_xaxes=True, print_grid=True,
vertical_spacing=0.05, horizontal_spacing=0.12,
specs=[[{"colspan": 3, "secondary_y":True}, None, None, {"secondary_y":True}],
[{"colspan": 3, "secondary_y":True}, None, None, {"secondary_y":True}],
[{"colspan": 3, "secondary_y":True}, None, None, {"secondary_y":True}]]
)
config = dict({'scrollZoom': True})
fig.layout['xaxis']['matches'] = 'x5'
fig.layout['xaxis3']['matches'] = 'x5'
fig.layout['xaxis2']['matches'] = 'x5'
fig.layout['xaxis4']['matches'] = 'x5'
fig.layout['xaxis6']['matches'] = 'x5'
fig.layout['xaxis']['showticklabels'] = False
fig.layout['xaxis3']['showticklabels'] = False
fig.layout['xaxis5']['showticklabels'] = True
fig.layout['xaxis2']['showticklabels'] = False
fig.layout['xaxis4']['showticklabels'] = False
fig.layout['xaxis6']['showticklabels'] = True
for k in range(1, 4):
fig.add_trace(go.Scatter(x=np.arange(1, 6), y=(1+k)*np.random.rand(5)), k, 1, secondary_y=True)
for k in range(1, 4):
fig.add_trace(go.Scatter(x=np.arange(1, 6), y=2*np.random.rand(5)), k, 1, secondary_y=False)
fig.update_layout(yaxis2_range=[0,2], yaxis6_range=[0,3], yaxis10_range=[0,4])
for k in [2, 6, 10]:
fig.update_layout{f"yaxis{k}": {"title":{"text": f'y{k}'
}}})
Now let us revert the position of two yaxes associated to the same traces:
fig.update_layout(yaxis9_side="right", yaxis10_side="left")