To access the layout of the plotly. It is handy to override the attribute of the plot through fig.layout
For moving colorbar purpose:
In order to separate the 2 colorbars, after creating the first trace/figure, we can access its current reference position and override with new_value before adding another trace
fig.layout.coloraxis.colorbar.x = 1.5 => this will move the bar to the right (default is 1)
fig.layout.coloraxis.colorbar.x = -0.5 => this will move the bar to the left
the same idea will also apply to y value as well as colorscale.
For friendlier using purpose, you can use update method instead:
fig.update_coloraxes(colorbar_x=<VALUE>)
For further detail, you can check out here
Here is an example, where I change the colorbar and its color reference.
#creating a figure and add the first trace
fig = px.density_contour(df[(df["label"]=='capture')&(df["bie"]=='bie')], x="x", y="y")
# change reference params
fig.layout.coloraxis.colorbar.x = 1.1
fig.update_coloraxes(colorscale="YlGnBu")
fig.update_traces(contours_coloring="fill")
# add new traces with new params
fig.add_traces(
list(px.scatter(df[df["label"]=='capture'], x="x", y="y",color="state", opacity=0.8).select_traces()))
fig.update_layout(width=1000,height=500,legend=dict(
yanchor="bottom"))
fig.show()
