Shared legend between subplots of different types

Hi @xaviersjs, yes, that’s possible. Some information here:

Adapted to your needs:

from plotly.express.colors import sample_colorscale
import plotly.graph_objects as go
import numpy as np

DATAPOINTS = 50

#scaling function
def minmax_scale(y):
    return [(val - y.min()) / (y.max() - y.min()) for val in y]

# create data
x = np.ones(DATAPOINTS)
y = np.arange(0, DATAPOINTS)

discrete_viridis24 = sample_colorscale('Viridis', minmax_scale(y))


fig = go.Figure(
    go.Scatter(
        x=x, 
        y=y, 
        mode='markers', 
        marker={'size':10, 'color': discrete_viridis24}, 
        name='discrete viridis'
    )
)

fig.update_layout(
    width=600, 
    height=800
)

1 Like