How could I change a color scale for choropleth map?

How could I change the range scaling of n ma choropleth map? In dataset there are some very high values, and although I can try to use log scale, still think it won’t be the best decision. That’s why I wonder - is there a way to change color scaling, to give more space for low values and leave big ones in the top level of gauge?

For example, there is sample code, and on image I showed what do I need. Is it possible?

import plotly.express as px

dff = px.data.election()
geojson = px.data.election_geojson()

fig = px.choropleth(dff, geojson=geojson, color="Bergeron",
                    locations="district", featureidkey="properties.district",
                    projection="mercator"
                   )
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

This answer may be similar to what you are wanting to do?

Thanks, it helped me. For the code above it’ll be so:

import plotly.express as px

dff = px.data.election()
geojson = px.data.election_geojson()

fig = px.choropleth(dff, geojson=geojson, 
                    color="Bergeron",
                    locations="district", 
                    featureidkey="properties.district",
                     projection="mercator",
                   color_continuous_scale=[[0, 'rgb(240,240,240)'],
                      [0.05, 'rgb(13,136,198)'],
                      [0.1, 'rgb(191,247,202)'],
                      [0.20, 'rgb(4,145,32)'],
                      [1, 'rgb(227,26,28,0.5)']])
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
2 Likes