Show Sidebar Hide Sidebar

Mapbox Choropleth Maps in Python

How to make a Mapbox Choropleth Map of US Counties in Python with Plotly.

Mapbox Access Token

To plot on Mapbox maps with Plotly you may need a Mapbox account and a public Mapbox Access Token. See our Mapbox Map Layers documentation for more information.

Carto base map: no token needed

In [1]:
from urllib.request import urlopen
import json
with urlopen('') as response:
    counties = json.load(response)

import pandas as pd
unemp = pd.read_csv("",
                   dtype={"fips": str})

import plotly.graph_objects as go

fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=unemp.fips, z=unemp.unemp,
                                    colorscale="Viridis", zmin=0, zmax=12,
                                    marker_opacity=0.5, marker_line_width=0))
                  mapbox_zoom=3, mapbox_center = {"lat": 37.0902, "lon": -95.7129})