Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 67/ 160
04. Data Visualization & BI

Geospatial Mapping & Choropleths

Map metrics by region with choropleths and avoid misleading area-based encodings.

IntermediateGeoJSON · Choropleth3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

A choropleth colours each area of a map by a number, such as cases per 100,000 people, so you can see where the value is high or low.

Think of it like…

Painting rooms in a building by how crowded they are: counting people in each room favours big rooms, so you divide by room size (a rate), pick colour bands that separate typical rooms, and draw the plan to scale.

Where you’ve seen it

A health analyst maps flu cases by US state. California reports 10,000 cases and Wyoming 400, so the count map shades California darkest. But California has 39 million residents and Wyoming 0.58 million, so the rates are 10,000 / 39,000,000 × 100,000 = 25.6 and 400 / 580,000 × 100,000 = 69.0 cases per 100,000: Wyoming's rate is nearly three times higher. The analyst joins a state GeoDataFrame to the rates on a string FIPS code (keeping leading zeros: "06", not 6), classifies the rates into five quantile classes of ten states each so colours spread evenly, uses a single-hue sequential palette, draws the map in an Albers equal-area projection and adds a small table of the top five states because tiny regions such as Rhode Island are hard to see.

Words you’ll hear

Choropleth
A map that shades regions by a normalised value.
Classification scheme
How values are grouped into colour classes: equal interval, quantiles or natural breaks.
Equal-area projection
A map projection that preserves relative area, such as Albers or Equal Earth.
MAUP
The modifiable areal unit problem: patterns change with how regions are drawn or aggregated.

Visual diagram

Loading interactive diagram

Theory & deep dive

Data, joins and normalisation

Load boundaries with gpd.read_file("states.geojson") and merge your metrics with gdf.merge(df, on="fips", how="left"). Join keys are the top failure source: FIPS codes need to be strings with leading zeros ("06", "01001"), names differ across sources ("St. Louis" versus "Saint Louis"), and boundaries change over time (counties merge, postcodes are reassigned). After merging, check gdf["rate"].isna().sum() and list unmatched keys so missing regions aren't shown as zero or silently omitted; decide explicitly how to display "no data" (grey with a legend entry), distinct from a true zero.

Normalise counts to a rate: per 100,000 people, per household, per km² or as a share of a total, choosing a denominator that makes regions comparable. Be careful with small populations, where rates are volatile (one case in a county of 500 is 200 per 100,000): consider empirical Bayes smoothing, a minimum population threshold or showing confidence intervals in tooltips. Use bubble or proportional-symbol maps or cartograms for raw counts, where the size of a symbol encodes the quantity without painting entire areas.

Count versus rate

California: 10,000 cases, 39,000,000 people → 25.6 per 100,000. Wyoming: 400 cases, 580,000 people → 69.0 per 100,000. A count map says "California"; the rate map says "Wyoming", which is the more useful signal for resource allocation.

Key takeaway: Join on clean string codes, handle missing regions explicitly and map rates, using symbols for counts.

Classification, colour and projection

A classification scheme turns a continuous value into 5 to 7 colour classes. Equal interval gives each class the same width, which suits uniformly spread data but, with one outlier, puts nearly every region in the lowest classes. Quantiles put an equal number of regions in each class, spreading colours evenly but potentially grouping very different values and splitting similar ones. Natural breaks (Jenks) and mapclassify schemes such as FisherJenks or HeadTailBreaks find gaps in the data. Whatever you pick, show the class boundaries in the legend, use a sequential palette (a single hue light to dark) for rates, a diverging one only when there's a meaningful midpoint (change from national average), and test the palette for colour-vision accessibility.

Projection matters because the globe can't be flattened without distortion. Web Mercator, the default for web tiles, inflates areas near the poles: Greenland (2.2 million km²) looks as large as Africa (30.4 million km²), which is about 14 times bigger. For choropleths, where area carries visual weight, use an equal-area projection (Albers for the contiguous US, Equal Earth or Mollweide for the world; in GeoPandas gdf.to_crs("EPSG:5070") for US Albers). Remember the MAUP: patterns can change when the same data is aggregated to counties instead of states or postcodes, and large sparsely populated areas dominate the visual impression even if few people live there. In Plotly, px.choropleth(df, geojson=gj, locations="fips", color="rate", featureidkey="properties.GEOID", scope="usa") gives an interactive version.

Equal interval vs quantile

State rates range from 5 to 70 per 100,000, but 45 of 50 states are below 30. Five equal-interval classes of width 13 put most states in the lowest two colours and the map looks uniform; five quantile classes give 10 states each and show regional contrast, while the legend states the class limits.

Key takeaway: Pick the classification deliberately, use an ordered palette and an equal-area projection, and label limits and sources.

How it works, step by step

Step 1 of 4
Analyst

1. Prepare geometry and keys

Load boundaries, standardise region codes as strings and verify the join covers all regions.

fips as string: "06"
Key numbers at this step
Check
unmatched keys

When to use it & trade-offs

What it is

A choropleth colours geographic regions (states, counties, postcodes) by a value. It works only when the value is a normalised rate or density (cases per 100,000 people, revenue per store, share of households), because region size and population vary widely and raw counts mostly show where more people or bigger areas are. Building one involves geometry (GeoJSON or shapefiles read with GeoPandas), a reliable join key (FIPS, ISO or postcode codes), a classification scheme (equal interval, quantile, natural breaks) with a perceptually ordered colour scale, and a sensible projection.

Why it matters: Maps are intuitive but easy to get wrong: a count map mostly reproduces the population map, equal-interval colours can hide almost all variation behind one outlier, a Mercator projection exaggerates high-latitude areas, and bad join keys silently drop regions. Analysts who understand these pitfalls produce maps that inform location decisions (store placement, public-health response, delivery zones) instead of misleading them.

When to reach for it

  • Public-health, sales or logistics patterns by region
  • Choosing sites or territories
  • Executive dashboards with geographic breakdowns

When to avoid or be careful

  • Choropleths of raw counts
  • Mercator for area-based colour maps
  • Treating missing regions as zero

Ways to map a metric

Choropleth of rates
Best for: Comparing normalised values across regions

Strengths: Intuitive; fills the map.

Watch out: Large regions dominate; needs normalisation.

Proportional symbol or bubble map
Best for: Raw counts and totals

Strengths: Avoids area bias; small regions remain visible.

Watch out: Symbols can overlap.

Cartogram or tile map
Best for: Equalising visual weight (by population)

Strengths: Small, dense regions become visible.

Watch out: Distorts geography; less familiar.

Interview signals & numbers to know

When this topic comes up

  • “The map just looks like the population map”
  • “Join by FIPS loses regions”
  • Equal interval versus quantile
  • Map projections
  • Modifiable areal unit problem

Benchmarks & rules of thumb

25.6 vs 69.0 -
per-100,000 rates behind the California and Wyoming example
5 – 7 -
classes in a typical choropleth
~14× -
Africa's area relative to Greenland

Common mistakes & follow-ups

Common interview mistakes

  • Joining on integer FIPS codes and losing leading zeros.
  • Using a rainbow palette for an ordered rate.
  • Ignoring that tiny regions are invisible on a map.

Likely interviewer follow-ups

  • Why not map raw counts with a choropleth?
  • How do you choose class breaks?
  • What is the modifiable areal unit problem?
Interview tip: Show the count-versus-rate flip (California versus Wyoming). It is a memorable proof that normalisation changes the conclusion.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Geospatial Mapping & Choropleths with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Interactive Charts with Plotly
Next topic
Power BI / Tableau Interface & Data Connectors