How do you put a discrete colorbar on a density mapbox map? (Python)

Hello!
I have a density mapbox and wanted to put a colorbar with discrete colors and not be continuous.
My code is:

df=df[df[‘Hot Days’]>0]
fig =px.density_mapbox(df,
lat=‘lat’,
lon=‘lon’,
z=‘Hot Days’,
zoom=3.5,
color_discrete_scale=px.colors.sequential.Turbo,

radius=2,
opacity=0.5)

fig.update_layout(mapbox_style=“open-street-map”)
fig.update_layout(width=900,height=600,mapbox_center_lon=7, mapbox_center_lat=47)

plot(fig, auto_open=True)

And this makes:


and I want a colorbar like this:
colorbar
Thanks!

Hi,
@empet explained how you can achieve this in here

Hope it helps!

1 Like