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 !