Skip to content

Choropleth Maps

When to use a choropleth

A choropleth map colors geographic regions based on a value:

  • Covid cases by country
  • Sales by state
  • Population density

Example dataset (country metrics)

Example data
import pandas as pd
 
df = pd.DataFrame({
    "country": ["India", "United States", "Brazil"],
    "iso_alpha": ["IND", "USA", "BRA"],
    "value": [120, 200, 150],
})
print(df)
Example data
import pandas as pd
 
df = pd.DataFrame({
    "country": ["India", "United States", "Brazil"],
    "iso_alpha": ["IND", "USA", "BRA"],
    "value": [120, 200, 150],
})
print(df)

Plotly Express choropleth

Plotly works best with ISO-3 codes (iso_alphaiso_alpha).

Choropleth map
import plotly.express as px
 
fig = px.choropleth(
    df,
    locations="iso_alpha",
    color="value",
    hover_name="country",
    color_continuous_scale="Viridis",
    title="Metric by country",
)
 
fig.show()
Choropleth map
import plotly.express as px
 
fig = px.choropleth(
    df,
    locations="iso_alpha",
    color="value",
    hover_name="country",
    color_continuous_scale="Viridis",
    title="Metric by country",
)
 
fig.show()

Tips

  • Prefer ISO codes for reliable mapping.
  • Consider log scale for heavy-tailed metrics.
  • Always add a clear title and color legend.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did