Choropleth Map (Python)

Authors

[Editor] Shixiang Wang;

[Contributors] Claude Code โ€” AI-generated, independently AI-reviewed;

Modified

2026-10-19

๐Ÿค– AI Skill โ€” Download the Bizard unified skill for your AI assistant โฌ‡๏ธ Download Skill ZIP
๐Ÿ”Œ MCP Server โ€” Let AI agents (Claude Code, Cursor, โ€ฆ) query Bizard live: claude mcp add bizard -- npx @openbiox/bizard-mcp โ€” or the free hosted instance (no install, faster from mainland China): claude mcp add --transport http bizard http://biotree.top:38123/bizard-mcp/mcp ๐Ÿ“– MCP Docs
๐Ÿ“– Cite Bizard โ€” if Bizard helps your research, please cite: Li, K., Zheng, H., Huang, K., et al. (2026). Bizard: A Community-Driven Platform for Accelerating and Enhancing Biomedical Data Visualization. iMetaMed, e70038. ๐Ÿ”— DOI / BibTeX

A choropleth map shades geographic regions by a value โ€” incidence rates, cohort coverage, sequencing capacity โ€” making spatial inequality the first thing a reader sees. plotly.express.choropleth ships built-in country geometry, so a public-health map needs no GIS stack and no shapefile downloads.

Example

Setup

  • System Requirements: Cross-platform (Linux/MacOS/Windows)
  • Programming Language: Python
  • Dependencies: pandas, numpy, plotly
import pandas as pd
import numpy as np
import plotly.express as px

Data Preparation

We summarize a multi-country observational study: participating countries with enrolled patients and per-million incidence โ€” the two columns a choropleth needs, keyed by ISO-3 codes (built into plotlyโ€™s geometry).

study = pd.DataFrame({
    'ISO': ['BRA', 'CHN', 'DEU', 'GBR', 'IND', 'JPN', 'KEN', 'KOR',
            'NGA', 'USA', 'ZAF'],
    'Country': ['Brazil', 'China', 'Germany', 'United Kingdom', 'India',
                'Japan', 'Kenya', 'South Korea', 'Nigeria', 'United States',
                'South Africa'],
    'Patients': [312, 540, 288, 301, 265, 198, 74, 121, 66, 430, 96],
})
pop_m = dict(BRA=216, CHN=1412, DEU=84, GBR=68, IND=1428, JPN=124,
             KEN=55, KOR=52, NGA=223, USA=335, ZAF=60)
study['PerMillion'] = (study.Patients / study.ISO.map(pop_m)).round(1)

Visualization

Enrolment Intensity Map

locations takes the ISO-3 codes and color the value; a perceptually uniform scale and an explicit range_color keep two figures comparable.

fig = px.choropleth(
    study, locations='ISO', color='PerMillion',
    hover_name='Country',
    hover_data={'Patients': True, 'PerMillion': ':.1f', 'ISO': False},
    color_continuous_scale='Viridis',
    range_color=(0, study.PerMillion.max()),
    labels={'PerMillion': 'Patients per million'})
fig.update_layout(geo=dict(showframe=False, showcoastlines=False,
                           projection_type='natural earth'),
                  width=860, height=460, font_size=11,
                  margin=dict(l=10, r=10, t=30, b=10))
fig.show()
Figureย 1: Study enrolment per million population by country

Highlighting Non-Participating Countries

Setting the non-participating countriesโ€™ value to NaN greys them out, turning absence itself into visible information โ€” often the honest choice for coverage maps.

all_iso = ['BRA', 'CHN', 'DEU', 'GBR', 'IND', 'JPN', 'KEN', 'KOR',
           'NGA', 'USA', 'ZAF', 'AUS', 'CAN', 'FRA', 'MEX', 'SWE']
coverage = study.set_index('ISO').reindex(all_iso)

fig = px.choropleth(
    coverage.reset_index(), locations='ISO', color='PerMillion',
    hover_name='ISO', color_continuous_scale='Viridis',
    labels={'ISO': 'Country', 'PerMillion': 'Patients per million'})
fig.update_traces(marker_line_color='#737373', marker_line_width=0.5)
fig.update_layout(geo=dict(showframe=False, showcoastlines=False,
                           landcolor='#eeeeee',
                           projection_type='natural earth'),
                  width=860, height=460, font_size=11,
                  margin=dict(l=10, r=10, t=30, b=10))
fig.show()
Figureย 2: Participating countries shaded; non-participants left grey

References

  1. Plotly Technologies Inc.ย Choropleth map in Python. https://plotly.com/python/choropleth-maps/
  2. Crameri, F., Shephard, G. E., & Heron, P. J. (2020). The misuse of colour in science communication. Nature Communications, 11, 5444.