✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Choropleth - how to override values displayed in legend?

fig = px.choropleth(ts_short, geojson=counties, locations='FIPS', color='5/10/20',
                    color_continuous_scale="Inferno",
                    range_color=(dmin, dmax),
                    scope="usa"
)

ts_short is a Pandas dataframe with two columns: FIPS provides location codes, and 5/10/20 provides values.

But the values column is not linear, it was processed through a gamma function that boosts small values. So the numbers shown in the legend are not accurate. The top and the bottom remain true, but the lower numbers need to be pushed up a bit.

Is there a way to provide a list of labels or something that could override the numbers displayed on the legend?

Related issue - again legend control: the string printed at the top of the legend is the name of the column. I tried to override it like this:

fig.update_layout(
    legend_title_text='daily values'
)

…but it makes no difference. How to override the text at the top of the legend?

I’m away from my computer so I can just provide a short hint: the gradient guide on the side there is called a “colorbar” in Plotly parlance, rather than a legend, so you’ll have to use the corresponding attributes :slight_smile:

1 Like

@FlorinAndrei

To update the ticklabels of your colorbar you should update the coloraxis_colorbar defined in layout

fig.update_layout(coloraxis_colorbar= dict(tickvals=[...], ticktext=[...] ,  title='new_title'))

The tickvals is the list of actual displayed values on colorbar , while ticktext is the list of new values or text that you want to be displayed.

1 Like