A choropleth map visualizes data by shading geographic regions (countries, states, or counties) according to a measured variable. This technique is ideal for showing regional patterns and spatial distributions, making it easy to identify areas with high or low values at a glance. The color intensity represents the data magnitude, creating an intuitive way to understand geographic variation.

""" anyplot.ai
choropleth-basic: Choropleth Map with Regional Coloring
Library: letsplot 4.9.0 | Python 3.13.13
Quality: 88/100 | Updated: 2026-05-15
"""
import os
import pandas as pd
from lets_plot import *
from lets_plot.export import ggsave as export_ggsave
from lets_plot.geo_data import geocode_countries
LetsPlot.setup_html()
# Theme tokens
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
NA_COLOR = "#D0CFC8" if THEME == "light" else "#5A5953"
BORDER_COLOR = "#3A3934" if THEME == "light" else "#D8D7D0"
# Data: GDP per capita by European countries (in thousands USD)
data = {
"country": [
"Germany",
"France",
"Italy",
"Spain",
"Poland",
"Netherlands",
"Belgium",
"Sweden",
"Austria",
"Switzerland",
"Norway",
"Denmark",
"Finland",
"Ireland",
"Portugal",
"Czech Republic",
"Greece",
"Hungary",
"Romania",
"Bulgaria",
"Slovakia",
"Croatia",
"Slovenia",
"Lithuania",
"Latvia",
"Estonia",
"Luxembourg",
],
"gdp_per_capita": [
48.7,
42.3,
34.5,
30.1,
17.8,
57.0,
51.2,
55.7,
53.3,
92.4,
89.2,
67.8,
53.2,
100.2,
24.5,
27.0,
20.2,
18.8,
15.1,
13.9,
21.3,
18.5,
28.4,
24.0,
21.8,
28.3,
126.4,
],
}
df = pd.DataFrame(data)
# Get country boundaries
countries = geocode_countries(df["country"].tolist()).get_boundaries()
df_geo = countries.merge(df, left_on="found name", right_on="country", how="left")
# Create choropleth map with European focus
plot = (
ggplot()
+ geom_map(
aes(fill="gdp_per_capita"),
data=df,
map=df_geo,
map_join=["country", "found name"],
color=BORDER_COLOR,
size=1.0,
alpha=1.0,
)
+ scale_fill_viridis(name="GDP per Capita\n(thousands USD)", na_value=NA_COLOR)
+ labs(title="choropleth-basic · letsplot · anyplot.ai")
+ coord_cartesian(xlim=[-12, 32], ylim=[35, 71])
+ ggsize(1600, 900)
+ theme_minimal()
+ theme(
plot_title=element_text(size=24, color=INK),
legend_title=element_text(size=18, color=INK),
legend_text=element_text(size=18, color=INK_SOFT),
legend_position=[0.82, 0.25],
axis_title=element_blank(),
axis_text=element_blank(),
axis_ticks=element_blank(),
panel_grid=element_blank(),
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
legend_background=element_rect(fill=ELEVATED_BG, color=INK_SOFT),
)
)
# Save as PNG (scale 3x for 4800 × 2700 px)
export_ggsave(plot, f"plot-{THEME}.png", path=".", scale=3)
# Save interactive HTML
export_ggsave(plot, f"plot-{THEME}.html", path=".")
Part of Choropleth Map with Regional Coloring on anyplot.ai.