Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

Having Two scales on Scatter Plot

Hello! I am having difficulties understanding how to create two color bars for two sets of scatter points.

This is giving me the look I want but I don’t understand why Option 2 is not working.
Do all the updates/configuration of coloraxis2 need to happen outside the adding trace?

Thanks,

fig = go.Figure(data = go.Scatter(x=[-9, -6, -5 , -3, -1], 
                                  y=[0, 1, 4, 5, 7] ,  
                                  marker_color = [1, 9, 2, 0, 5],
                                  marker_coloraxis = 'coloraxis',
                                 mode = 'markers',
                                 marker_size = 15))

fig.layout.coloraxis2 = fig.layout.coloraxis          #Why do I need this?

fig.add_trace( go.Scatter(x=[2,4,8,10,-4], 
                                  y=[0, 1, 4, 5, 7] ,  
                                  marker_color = [0, 0, 2, 8, 4],
                                 marker_coloraxis = 'coloraxis2',
                                 name = 'Plot2',
                                 mode = 'markers',
                                 marker_size = 15))

fig.layout.coloraxis2 = dict(   colorbar_x = -0.2,
                                colorscale = 'Cividis',
                                colorbar_borderwidth = 5)

fig.show()


####################################################
####################################################
# OPTION 2

fig = go.Figure(data = go.Scatter(x=[-9, -6, -5 , -3, -1], 
                                  y=[0, 1, 4, 5, 7] ,  
                                  marker_color = [1, 9, 2, 0, 5],
                                  marker_coloraxis = 'coloraxis',
                                 mode = 'markers',
                                 marker_size = 15))

fig.layout.coloraxis2 = fig.layout.coloraxis

fig.add_trace( go.Scatter(x=[2,4,8,10,-4], 
                                  y=[0, 1, 4, 5, 7] ,  
                                  marker_color = [0, 0, 2, 8, 4],
                                 marker_coloraxis = 'coloraxis2',
                                 name = 'Plot2',
                                 mode = 'markers',
                                 marker_size = 15))

# COMMENT: I thought that by associating the marker in second trace to "coloraxis2", then using the update_trace should have worked

fig.update_traces(marker_size=40,  selector=dict(name='Plot2'))
fig.update_traces(marker_colorbar_x = -0.2 ,  selector=dict(name='Plot2'))               
                  

fig.show()