USA County Choropleth Maps in Python

How to create colormaped representations of USA counties by FIPS values in Python.


New to Plotly?

Plotly is a free and open-source graphing library for Python. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

Deprecation warning

This page describes a legacy "figure factory" method for creating map-like figures using self-filled scatter traces. This is no longer the recommended way to make county-level choropleth maps, instead we recommend using a GeoJSON-based approach to making outline choropleth maps or the alternative tile-based choropleth maps.

Required Packages

plotly_geo, geopandas, pyshp and shapely must be installed for this figure factory to run.

Run the following commands to install the correct versions of the following modules:

In [1]:
!pip install plotly-geo==1.0.0
!pip install geopandas==0.8.1
!pip install pyshp==2.1.2
!pip install shapely==1.7.1
Collecting plotly-geo==1.0.0
  Downloading plotly_geo-1.0.0-py3-none-any.whl.metadata (834 bytes)
Downloading plotly_geo-1.0.0-py3-none-any.whl (23.7 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 23.7/23.7 MB 186.4 MB/s eta 0:00:00
Installing collected packages: plotly-geo
Successfully installed plotly-geo-1.0.0

[notice] A new release of pip is available: 24.3.1 -> 25.0.1
[notice] To update, run: pip install --upgrade pip
Collecting geopandas==0.8.1
  Downloading geopandas-0.8.1-py2.py3-none-any.whl.metadata (892 bytes)
Collecting pandas>=0.23.0 (from geopandas==0.8.1)
  Downloading pandas-2.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (89 kB)
Collecting shapely (from geopandas==0.8.1)
  Downloading shapely-2.0.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.8 kB)
Collecting fiona (from geopandas==0.8.1)
  Downloading fiona-1.10.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (56 kB)
Collecting pyproj>=2.2.0 (from geopandas==0.8.1)
  Downloading pyproj-3.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (31 kB)
Collecting numpy>=1.22.4 (from pandas>=0.23.0->geopandas==0.8.1)
  Downloading numpy-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
Collecting python-dateutil>=2.8.2 (from pandas>=0.23.0->geopandas==0.8.1)
  Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl.metadata (8.4 kB)
Collecting pytz>=2020.1 (from pandas>=0.23.0->geopandas==0.8.1)
  Downloading pytz-2025.1-py2.py3-none-any.whl.metadata (22 kB)
Collecting tzdata>=2022.7 (from pandas>=0.23.0->geopandas==0.8.1)
  Downloading tzdata-2025.1-py2.py3-none-any.whl.metadata (1.4 kB)
Requirement already satisfied: certifi in /home/circleci/.pyenv/versions/3.9.21/lib/python3.9/site-packages (from pyproj>=2.2.0->geopandas==0.8.1) (2024.8.30)
Collecting attrs>=19.2.0 (from fiona->geopandas==0.8.1)
  Downloading attrs-25.3.0-py3-none-any.whl.metadata (10 kB)
Requirement already satisfied: click~=8.0 in /home/circleci/.local/lib/python3.9/site-packages (from fiona->geopandas==0.8.1) (8.1.7)
Collecting click-plugins>=1.0 (from fiona->geopandas==0.8.1)
  Downloading click_plugins-1.1.1-py2.py3-none-any.whl.metadata (6.4 kB)
Collecting cligj>=0.5 (from fiona->geopandas==0.8.1)
  Downloading cligj-0.7.2-py3-none-any.whl.metadata (5.0 kB)
Collecting importlib-metadata (from fiona->geopandas==0.8.1)
  Downloading importlib_metadata-8.6.1-py3-none-any.whl.metadata (4.7 kB)
Collecting six>=1.5 (from python-dateutil>=2.8.2->pandas>=0.23.0->geopandas==0.8.1)
  Downloading six-1.17.0-py2.py3-none-any.whl.metadata (1.7 kB)
Collecting zipp>=3.20 (from importlib-metadata->fiona->geopandas==0.8.1)
  Using cached zipp-3.21.0-py3-none-any.whl.metadata (3.7 kB)
Downloading geopandas-0.8.1-py2.py3-none-any.whl (962 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 962.8/962.8 kB 105.2 MB/s eta 0:00:00
Downloading pandas-2.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.1/13.1 MB 219.0 MB/s eta 0:00:00
Downloading pyproj-3.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.3/8.3 MB 186.7 MB/s eta 0:00:00
Downloading fiona-1.10.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.3/17.3 MB 164.7 MB/s eta 0:00:00
Downloading shapely-2.0.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.5/2.5 MB 136.5 MB/s eta 0:00:00
Downloading attrs-25.3.0-py3-none-any.whl (63 kB)
Downloading click_plugins-1.1.1-py2.py3-none-any.whl (7.5 kB)
Downloading cligj-0.7.2-py3-none-any.whl (7.1 kB)
Downloading numpy-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 19.5/19.5 MB 160.5 MB/s eta 0:00:00
Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
Downloading pytz-2025.1-py2.py3-none-any.whl (507 kB)
Downloading tzdata-2025.1-py2.py3-none-any.whl (346 kB)
Downloading importlib_metadata-8.6.1-py3-none-any.whl (26 kB)
Downloading six-1.17.0-py2.py3-none-any.whl (11 kB)
Using cached zipp-3.21.0-py3-none-any.whl (9.6 kB)
Installing collected packages: pytz, zipp, tzdata, six, pyproj, numpy, cligj, click-plugins, attrs, shapely, python-dateutil, importlib-metadata, pandas, fiona, geopandas
Successfully installed attrs-25.3.0 click-plugins-1.1.1 cligj-0.7.2 fiona-1.10.1 geopandas-0.8.1 importlib-metadata-8.6.1 numpy-2.0.2 pandas-2.2.3 pyproj-3.6.1 python-dateutil-2.9.0.post0 pytz-2025.1 shapely-2.0.7 six-1.17.0 tzdata-2025.1 zipp-3.21.0

[notice] A new release of pip is available: 24.3.1 -> 25.0.1
[notice] To update, run: pip install --upgrade pip
Collecting pyshp==2.1.2
  Downloading pyshp-2.1.2.tar.gz (217 kB)
  Preparing metadata (setup.py) ... - done
Building wheels for collected packages: pyshp
  Building wheel for pyshp (setup.py) ... - done
  Created wheel for pyshp: filename=pyshp-2.1.2-py3-none-any.whl size=36263 sha256=457a1b4caf0b4e5d5f6c8432ecf91eae185a10783c9e80a9c601a0247814c4f6
  Stored in directory: /home/circleci/.cache/pip/wheels/f6/71/55/8728cf20a761b0fbca9ea511b37197287c1fff00f02b74fc1f
Successfully built pyshp
Installing collected packages: pyshp
Successfully installed pyshp-2.1.2

[notice] A new release of pip is available: 24.3.1 -> 25.0.1
[notice] To update, run: pip install --upgrade pip
Collecting shapely==1.7.1
  Downloading Shapely-1.7.1-1-cp39-cp39-manylinux1_x86_64.whl.metadata (34 kB)
Downloading Shapely-1.7.1-1-cp39-cp39-manylinux1_x86_64.whl (1.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.0/1.0 MB 127.0 MB/s eta 0:00:00
Installing collected packages: shapely
  Attempting uninstall: shapely
    Found existing installation: shapely 2.0.7
    Uninstalling shapely-2.0.7:
      Successfully uninstalled shapely-2.0.7
Successfully installed shapely-1.7.1

[notice] A new release of pip is available: 24.3.1 -> 25.0.1
[notice] To update, run: pip install --upgrade pip

If you are using Windows, follow this post to properly install geopandas and dependencies: http://geoffboeing.com/2014/09/using-geopandas-windows/. If you are using Anaconda, do not use PIP to install the packages above. Instead use conda to install them:

conda install plotly conda install geopandas

FIPS and Values

Every US state and county has an assigned ID regulated by the US Federal Government under the term FIPS (Federal Information Processing Standards) codes. There are state codes and county codes: the 2016 state and county FIPS codes can be found at the US Census Website.

Combine a state FIPS code (eg. 06 for California) with a county FIPS code of the state (eg. 059 for Orange county) and this new state-county FIPS code (06059) uniquely refers to the specified state and county.

ff.create_choropleth only needs a list of FIPS codes and a list of values. Each FIPS code points to one county and each corresponding value in values determines the color of the county.

Simple Example

A simple example of this is a choropleth a few counties in California:

In [2]:
import plotly.figure_factory as ff

fips = ['06021', '06023', '06027',
        '06029', '06033', '06059',
        '06047', '06049', '06051',
        '06055', '06061']
values = range(len(fips))

fig = ff.create_choropleth(fips=fips, values=values)
fig.layout.template = None
fig.show()
/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:775: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:331: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:848: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:853: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

109876543210

Change the Scope

Even if your FIPS values belong to a single state, the scope defaults to the entire United States as displayed in the example above. Changing the scope of the choropleth shifts the zoom and position of the USA map. You can define the scope with a list of state names and the zoom will automatically adjust to include the state outlines of the selected states.

By default scope is set to ['USA'] which the API treats as identical to passing a list of all 50 state names:

['AK', 'AL', 'CA', ...]

State abbreviations (eg. CA) or the proper names (eg. California) as strings are accepted. If the state name is not recognized, the API will throw a Warning and indicate which FIPS values were ignored.

Another param used in the example below is binning_endpoints. If your values is a list of numbers, you can bin your values into half-open intervals on the real line.

In [3]:
import plotly.figure_factory as ff

import numpy as np
import pandas as pd

df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/minoritymajority.csv')
df_sample_r = df_sample[df_sample['STNAME'] == 'California']

values = df_sample_r['TOT_POP'].tolist()
fips = df_sample_r['FIPS'].tolist()

colorscale = [
    'rgb(193, 193, 193)',
    'rgb(239,239,239)',
    'rgb(195, 196, 222)',
    'rgb(144,148,194)',
    'rgb(101,104,168)',
    'rgb(65, 53, 132)'
]

fig = ff.create_choropleth(
    fips=fips, values=values, scope=['CA', 'AZ', 'Nevada', 'Oregon', ' Idaho'],
    binning_endpoints=[14348, 63983, 134827, 426762, 2081313], colorscale=colorscale,
    county_outline={'color': 'rgb(255,255,255)', 'width': 0.5}, round_legend_values=True,
    legend=dict(
      title=dict(
        text='Population by County'
      )
    ),
    title=dict(
      text='California and Nearby States'
    )
)
fig.layout.template = None
fig.show()
/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:809: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:331: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:358: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:848: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:853: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

Population by County< 14,34814,348 - 63,98363,983 - 134,827134,827 - 426,762426,762 - 2,081,313> 2,081,313California and Nearby States

Single State

In [4]:
import plotly.figure_factory as ff

import numpy as np
import pandas as pd

df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/minoritymajority.csv')
df_sample_r = df_sample[df_sample['STNAME'] == 'Florida']

values = df_sample_r['TOT_POP'].tolist()
fips = df_sample_r['FIPS'].tolist()

endpts = list(np.mgrid[min(values):max(values):4j])
colorscale = ["#030512","#1d1d3b","#323268","#3d4b94","#3e6ab0",
              "#4989bc","#60a7c7","#85c5d3","#b7e0e4","#eafcfd"]
fig = ff.create_choropleth(
    fips=fips, values=values, scope=['Florida'], show_state_data=True,
    colorscale=colorscale, binning_endpoints=endpts, round_legend_values=True,
    plot_bgcolor='rgb(229,229,229)',
    paper_bgcolor='rgb(229,229,229)',
    legend_title='Population by County',
    county_outline={'color': 'rgb(255,255,255)', 'width': 0.5},
    exponent_format=True,
)
fig.layout.template = None
fig.show()
/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:809: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:331: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:358: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:848: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:853: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

1.73M - 2.59M869.20K - 1.73M8.28K - 869.20K< 8.28KPopulation by County

Multiple States

In [5]:
import plotly.figure_factory as ff

import pandas as pd

NE_states = ['Connecticut', 'Maine', 'Massachusetts', 'New Hampshire', 'Rhode Island', 'Vermont']
df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/minoritymajority.csv')
df_sample_r = df_sample[df_sample['STNAME'].isin(NE_states)]

values = df_sample_r['TOT_POP'].tolist()
fips = df_sample_r['FIPS'].tolist()

colorscale = [
    'rgb(68.0, 1.0, 84.0)',
    'rgb(66.0, 64.0, 134.0)',
    'rgb(38.0, 130.0, 142.0)',
    'rgb(63.0, 188.0, 115.0)',
    'rgb(216.0, 226.0, 25.0)'
]

fig = ff.create_choropleth(
    fips=fips, values=values,
    scope=NE_states, county_outline={'color': 'rgb(255,255,255)', 'width': 0.5},
    legend_title='Population per county'

)
fig.update_layout(
    legend_x = 0,
    annotations = {'x': -0.12, 'xanchor': 'left'}
)

fig.layout.template = None
fig.show()
/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:775: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:331: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:358: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:848: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:853: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

153721593383589725986281380616375561874442668184562832355108249975946592340292229782028392127417021542319900518753016560216484315979515850415374615153914676113001612594612411912185311759910760989181820367685171540708686086960327594655748156211545585191049144482144756743985430743966838820367453669735191341803246232096311213063028924271092495817290170411029869836226Population per county

Simplify County, State Lines

Below is a choropleth that uses several other parameters. For a full list of all available params call help(ff.create_choropleth)

  • simplify_county determines the simplification factor for the counties. The larger the number, the fewer vertices and edges each polygon has. See http://toblerity.org/shapely/manual.html#object.simplify for more information.
  • simplify_state simplifies the state outline polygon. See the documentation for more information. Default for both simplify_county and simplify_state is 0.02

Note: This choropleth uses a divergent categorical colorscale. See http://react-colorscales.getforge.io/ for other cool colorscales.

In [6]:
import plotly.figure_factory as ff

import pandas as pd

scope = ['Oregon']
df_sample = pd.read_csv(
    'https://raw.githubusercontent.com/plotly/datasets/master/minoritymajority.csv'
)
df_sample_r = df_sample[df_sample['STNAME'].isin(scope)]

values = df_sample_r['TOT_POP'].tolist()
fips = df_sample_r['FIPS'].tolist()

colorscale = ["#8dd3c7", "#ffffb3", "#bebada", "#fb8072",
              "#80b1d3", "#fdb462", "#b3de69", "#fccde5",
              "#d9d9d9", "#bc80bd", "#ccebc5", "#ffed6f",
              "#8dd3c7", "#ffffb3", "#bebada", "#fb8072",
              "#80b1d3", "#fdb462", "#b3de69", "#fccde5",
              "#d9d9d9", "#bc80bd", "#ccebc5", "#ffed6f",
              "#8dd3c7", "#ffffb3", "#bebada", "#fb8072",
              "#80b1d3", "#fdb462", "#b3de69", "#fccde5",
              "#d9d9d9", "#bc80bd", "#ccebc5", "#ffed6f"]

fig = ff.create_choropleth(
    fips=fips, values=values, scope=scope,
    colorscale=colorscale, round_legend_values=True,
    simplify_county=0, simplify_state=0,
    county_outline={'color': 'rgb(15, 15, 55)', 'width': 0.5},
    state_outline={'width': 1},
    legend_title='pop. per county',
    title='Oregon'
)

fig.layout.template = None
fig.show()
/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:775: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:331: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:358: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:848: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:853: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

759256547672383857354542319985206412162277118360107164100255864308293076820763536591262534492864615137301306302575925487252872258422248217492072915909112447771731772126821195317321424Oregonpop. per county

The Entire USA

In [7]:
import plotly.figure_factory as ff

import numpy as np
import pandas as pd

df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/laucnty16.csv')
df_sample['State FIPS Code'] = df_sample['State FIPS Code'].apply(lambda x: str(x).zfill(2))
df_sample['County FIPS Code'] = df_sample['County FIPS Code'].apply(lambda x: str(x).zfill(3))
df_sample['FIPS'] = df_sample['State FIPS Code'] + df_sample['County FIPS Code']

colorscale = ["#f7fbff","#ebf3fb","#deebf7","#d2e3f3","#c6dbef","#b3d2e9","#9ecae1",
              "#85bcdb","#6baed6","#57a0ce","#4292c6","#3082be","#2171b5","#1361a9",
              "#08519c","#0b4083","#08306b"]
endpts = list(np.linspace(1, 12, len(colorscale) - 1))
fips = df_sample['FIPS'].tolist()
values = df_sample['Unemployment Rate (%)'].tolist()

fig = ff.create_choropleth(
    fips=fips, values=values,
    binning_endpoints=endpts,
    colorscale=colorscale,
    show_state_data=False,
    show_hover=True, centroid_marker={'opacity': 0},
    asp=2.9, title='USA by Unemployment %',
    legend_title='% unemployed'
)

fig.layout.template = None
fig.show()
/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:809: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:331: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:358: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:848: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

/home/circleci/project/doc/.venv/lib/python3.9/site-packages/plotly/figure_factory/_county_choropleth.py:853: ShapelyDeprecationWarning:

The 'type' attribute is deprecated, and will be removed in the future. You can use the 'geom_type' attribute instead.

> 12.011.27 - 12.010.53 - 11.279.8 - 10.539.07 - 9.88.33 - 9.077.6 - 8.336.87 - 7.66.13 - 6.875.4 - 6.134.67 - 5.43.93 - 4.673.2 - 3.932.47 - 3.21.73 - 2.471.0 - 1.73USA by Unemployment %% unemployed

Also see tile county choropleths made in Python: https://plotly.com/python/tile-county-choropleth/

Reference

For more info on ff.create_choropleth(), see the full function reference

What About Dash?

Dash is an open-source framework for building analytical applications, with no Javascript required, and it is tightly integrated with the Plotly graphing library.

Learn about how to install Dash at https://dash.plot.ly/installation.

Everywhere in this page that you see fig.show(), you can display the same figure in a Dash application by passing it to the figure argument of the Graph component from the built-in dash_core_components package like this:

import plotly.graph_objects as go # or plotly.express as px
fig = go.Figure() # or any Plotly Express function e.g. px.bar(...)
# fig.add_trace( ... )
# fig.update_layout( ... )

from dash import Dash, dcc, html

app = Dash()
app.layout = html.Div([
    dcc.Graph(figure=fig)
])

app.run_server(debug=True, use_reloader=False)  # Turn off reloader if inside Jupyter