Question on px.choropleth zmin zmax

Hi this is my first post, I am trying to make an animated COVID-19 choropleth on daily confirmed cases, everythign works fine, but I like to make the scale absolute so that way a few cases in the early days will not make the state look so ā€œredā€.

my code is below:

fig = px.choropleth(usa_full, locations=ā€˜State’, title=ā€˜Confirmed Cases In Each State Over time’,
color=ā€˜Confirmed’,
locationmode=ā€˜USA-states’,
scope=ā€˜usa’,
hover_name=ā€˜Province_State’,
color_continuous_scale=px.colors.sequential.YlOrRd,
animation_frame=ā€˜Date’
)

fig.show()

I tried to add zauto zmin zmax in the px.choropleth it gave me error

TypeError: choropleth() got an unexpected keyword argument ā€˜zauto’

and using something like

fig.update_traces(zauto=False, zmin=0, zmax=400000)

has no effect, no error either.

Also, would be really nice if someone can telle me how to add state abbr on the map, e.g. showing ā€˜CA’ at california, ā€˜TX’ at texas.

my plotly version is:

import plotly
print(plotly.version)
4.8.1

Thank you for your time.

When using px.choropleth you’ll want to use the range_color=[<min>,<max>] argument.

The reason fig.update_traces(zauto=False, zmin=0, zmax=400000) isn’t working is that px uses layout.coloraxis rather than per-trace color axes. See https://plotly.com/python/colorscales/ for more information :slight_smile:

range_color=[<min>,<max>] works.

Thank you so much !