Skip to main content
Data Visualization
CHAPTER 21 Beginner

Geographic and Map Visualizations

Updated: May 18, 2026
5 min read

# CHAPTER 21

Geographic and Map Visualizations

1. Chapter Introduction

When your data has a geographic dimension — sales by country, stores by city, disease spread by region — maps communicate what tables never can. This chapter creates choropleth maps, bubble maps, and location-based analytics using Plotly.

2. Choropleth Map (Country-Level)

python
1234567891011121314151617181920212223242526272829303132333435363738394041424344
import plotly.express as px
import pandas as pd
import numpy as np

# Country-level revenue data
countries = pd.DataFrame({
    'Country': ['United States', 'Germany', 'United Kingdom', 'France', 'Japan',
                'China', 'India', 'Brazil', 'Canada', 'Australia'],
    'ISO_Alpha': ['USA', 'DEU', 'GBR', 'FRA', 'JPN', 'CHN', 'IND', 'BRA', 'CAN', 'AUS'],
    'Revenue': [2850000, 1420000, 1180000, 980000, 870000,
                1650000, 720000, 560000, 740000, 430000],
    'Growth': [12.3, 8.7, 6.2, 9.1, -2.3, 18.5, 24.8, 7.6, 10.2, 5.4]
})

# Revenue choropleth
fig = px.choropleth(countries,
                     locations='ISO_Alpha',
                     color='Revenue',
                     hover_name='Country',
                     hover_data={'Revenue': ':$,.0f', 'Growth': ':.1f%'},
                     color_continuous_scale=px.colors.sequential.Blues,
                     title='Global Revenue by Country — 2024',
                     template='plotly_white')
fig.update_geos(showcoastlines=True, coastlinecolor='#CCCCCC',
                 showland=True, landcolor='#F5F5F5',
                 showocean=True, oceancolor='#E3F2FD')
fig.update_layout(height=500, coloraxis_colorbar_title='Revenue ($)')
fig.show()
# fig.write_html('global_revenue.html')

# Growth choropleth (diverging — positive/negative)
fig2 = px.choropleth(countries,
                      locations='ISO_Alpha',
                      color='Growth',
                      hover_name='Country',
                      color_continuous_scale='RdBu',
                      color_continuous_midpoint=0,   # White = 0% growth
                      title='Revenue Growth Rate by Country (%)',
                      template='plotly_white')
fig2.update_geos(showcoastlines=True, coastlinecolor='gray',
                  showland=True, landcolor='#EEEEEE',
                  showocean=True, oceancolor='lightblue')
fig2.update_layout(height=500)
fig2.show()

3. Bubble Map (City-Level)

python
12345678910111213141516171819202122232425262728
import plotly.express as px
import pandas as pd

# Store locations
stores = pd.DataFrame({
    'City': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix',
              'Philadelphia', 'San Antonio', 'San Diego', 'Dallas', 'San Jose'],
    'Lat': [40.71, 34.05, 41.88, 29.76, 33.45, 39.95, 29.42, 32.72, 32.78, 37.34],
    'Lon': [-74.01, -118.24, -87.63, -95.37, -112.07, -75.17, -98.49, -117.16, -96.80, -121.89],
    'Revenue': [2850, 2100, 1580, 1230, 980, 870, 760, 820, 1450, 1100],
    'Customers': [48000, 36000, 28000, 21000, 17000, 15000, 13000, 14000, 25000, 19000],
    'Category': ['Flagship', 'Flagship', 'Regional', 'Regional', 'Standard',
                  'Standard', 'Standard', 'Standard', 'Regional', 'Regional']
})

fig = px.scatter_geo(stores,
                      lat='Lat', lon='Lon',
                      size='Revenue',
                      color='Category',
                      hover_name='City',
                      hover_data={'Revenue': ':$,.0f K', 'Customers': ':,', 'Lat': False, 'Lon': False},
                      size_max=40,
                      color_discrete_map={'Flagship': '#1565C0', 'Regional': '#2E7D32', 'Standard': '#FF9800'},
                      scope='usa',
                      title='US Store Performance Map (Bubble Size = Revenue)',
                      template='plotly_white')
fig.update_layout(height=500)
fig.show()

4. Common Mistakes

  • Using sequential colormap for growth data: Growth can be negative or positive — use diverging RdBu with colorcontinuousmidpoint=0 so 0% = white.
  • Bubble maps without size legend: Viewers can't interpret bubble size without a reference. Always include sizemax and a clear title explaining what size encodes.

5. MCQs

Question 1

Choropleth map encodes values using?

Question 2

colorcontinuousmidpoint=0 in Plotly?

Question 3

scope='usa' in scattergeo?

Question 4

Diverging colormap for geographic growth data?

Question 5

Bubble map encodes quantity using?

Question 6

locations='ISOAlpha' tells Plotly?

Question 7

hoverdata={'Revenue': ':$,.0f'} shows on hover?

Question 8

showocean=True, oceancolor='lightblue' in geo?

Question 9

Best map type for comparing values across countries?

Question 10

City-level granularity requires?

6. Interview Questions

  • Q: What is a choropleth map and when do you use it?
  • Q: How does a bubble map differ from a choropleth map?

7. Summary

Geographic visualizations: choropleth for country/region-level values (color = value), bubble map for location points (size = value). Use RdBu with midpoint=0 for growth/change data. Plotly's px.choropleth handles country matching via ISO codes. Always include hover data for interactive detail.

8. Next Chapter Recommendation

In Chapter 22: Real-Time Data Visualization, we build live-updating charts using Plotly Dash for streaming data and real-time dashboards.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·