Duplicate of Is it possible for multiple traces to share the same colorscale?,
But i didn’t find any answer despite the fact that github issue is already closed(
We now have brand new documentation for this! https://plot.ly/python/colorscales/#share-color-axis The answer is to share a coloraxis between traces.
The simple answer is to use coloraxis="coloraxis"
as below. This forces synchronization of the colorscales between the trace objects:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig = make_subplots(1,2)
fig.add_trace(
go.Heatmap(
x = [1, 2, 3, 4], z = [[1, 2, 3, 4], [4, -3, -1, 1]],
coloraxis = "coloraxis"
),
1,1
)
fig.add_trace(
go.Heatmap(
x = [3, 4, 5, 6], z = [[10, 2, 1, 0], [4, 3, 5, 6]],
coloraxis = "coloraxis"
),
1,2
)
fig.update_layout(coloraxis = {'colorscale':'viridis'})
fig.show()
In case you are using marker objects in a scatter plot, do the same
.
.
fig = go.Figure(data=[
# trace 0
go.Scatter3d(
x=xyz1[...,0], y=xyz1[...,1], z=xyz1[...,2],
mode='markers',
marker=dict(
size=5,
color=values1, # <- values plotted as color of point
coloraxis='coloraxis'
)
),
# trace 1
go.Scatter3d(
x=xyz2[...,0], y=xyz2[...,1], z=xyz2[...,2],
mode='markers',
marker=dict(
size=5,
color=values2, # <- values plotted as color of point
coloraxis='coloraxis'
)
),
])
fig.update_layout(coloraxis={'colorscale':'viridis'})
fig.update_scenes(aspectmode='data')
fig.show()