@vaclavku I didn’t notice that your project is a dash one, because the question wasn’t related to dash.
- You can update your initial fig. The conversion to
go.FigureWidget
isn’t necessary. I did it for displaying faster the figure.
- In this case (i.e. no conversion to
go.FigureWidget
) you can perfom the updates on dicts if you prefer this form:
fig['data'][4].update(yaxis='y5')
fig['layout'].update(width=600, height=500,
yaxis5=dict(overlaying='y4',
side='right',
anchor='x4',
range=[10, 30],
showgrid=False,
title='right title'),
hovermode='closest')
I’m not sure if I undesrstood your last question. It seems that you assigned the yaxis='y9'
in your trace definition. In my example the axes assignments are performed by the lines of code:
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.append_trace(trace5, 2, 2)
If you print the fig after these appends you’ll see:
print(fig)
(Scatter({
'uid': 'c88b9eea-8be1-4a61-86df-c768bc47b513', 'x': [1, 2, 3], 'xaxis': 'x', 'y': [2, 4, 3], 'yaxis': 'y'
}), Scatter({
'uid': '0a188393-2cfc-4fb0-99b3-feab35697970', 'x': [20, 30, 40], 'xaxis': 'x2', 'y': [7, 5, 3], 'yaxis': 'y2'
}), Scatter({
'uid': '16eac9fd-f525-4f22-9209-2b82c415e697', 'x': [2, 3, 4], 'xaxis': 'x3', 'y': [60, 70, 80], 'yaxis': 'y3'
}), Scatter({
'uid': 'f216bc77-a156-4734-93bf-52d6cb8789e6',
'x': [40, 50, 60, 70],
'xaxis': 'x4',
'y': [70, 90, 50, 65],
'yaxis': 'y4'
}), Scatter({
'uid': 'fc125392-8abe-4b48-b49b-19f2efc8cd99',
'x': [40, 50, 60, 70],
'xaxis': 'x4',
'y': [11, 15, 27, 23],
'yaxis': 'y4'
}))
Hence both trace4 and trace5 are referenced to xaxis4, yaxis4
. That’s why is necessary the following update:
fig['data'][4].update(yaxis='y5') # or equivalently fig.data[4].update(yaxis='y5')
But if you don’t define the subplots via tls.make_subplots
, but specifying in each trace its xaxis and yaxis,
no update is necessary on fig['data'][4]
.
You should update only fig[‘layout’].
The traces whose yaxis have not set side='right'
in layout, are supposed to have side='left'
by default.