Coloring a map with number ranges?

I took the below code off of the plotly choropleth tutorial section. How would I change the legend & color coding to use number ranges. For example, instead of 0 to 12, have it color the ranges 0-3, 4-6, 9-12?

from urllib.request import urlopen
import json
with urlopen(‘’) as response:
counties = json.load(response)

import pandas as pd
df = pd.read_csv(“”,
dtype={“fips”: str})

import as px

fig = px.choropleth(df, geojson=counties, locations=‘fips’, color=‘unemp’,
range_color=(0, 12),
labels={‘unemp’:‘unemployment rate’}

We’ve got some documentation about how to create a discrete color scale here:

Thank you for the quick answer!

How about making the legend look like this? Not so much the circles but the number ranges.


Yep, a little lower down on the same page there’s an example that shows how to customize the tick text:

Ok this is great. I believe this is exactly what I need. Now I just need to make the tick vals, tick text and color scale all work together and deal with some outliers in my data.

Thx again.