Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Plotting choropleth maps with Cartopy @ PyData ...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
alinagator
November 03, 2015
Programming
1.5k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Plotting choropleth maps with Cartopy @ PyData London
alinagator
November 03, 2015
Other Decks in Programming
See All in Programming
phperだってパンチカードでコーディングしたい
o0h
PRO
0
340
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
Workers Cache を知る
syumai
0
370
sbt 2.0: takeoff
eed3si9n
0
160
APNsからLive Activityを開始する話
yumnumm
0
170
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
230
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.2k
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
すこし踏み込む CancellationToken
htkym
2
1.7k
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
340
How to Ace a Technical Interview
jacobian
280
24k
The browser strikes back
jonoalderson
0
1.8k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Tell your own story through comics
letsgokoyo
1
1.1k
Mind Mapping
helmedeiros
1
400
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
330
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Transcript
Plotting choropleth maps with Cartopy Alina Solovjova
So what is a choropleth map?
There are online tools that do this • CartoDB -
cartodb.com • Google Fusion Tables - bit.ly/g-fusion • OpenHeatMap - openheatmap.com What about Python??
pip install cartopy
Let’s plot a map of the world import matplotlib.pyplot as
plt import cartopy.crs as ccrs ax = plt.axes(projection=ccrs.PlateCarree()) ax.coastlines() ax.stock_img()
I’m only interested in the UK, so let’s zoom in
import matplotlib.pyplot as plt import cartopy.crs as ccrs ax = plt.axes(projection=ccrs.PlateCarree()) ax.coastlines() ax.set_extent([-12, 3, 49, 60]) // x0,x1,y0,y1
Increase the resolution of the coastline import matplotlib.pyplot as plt
import cartopy.crs as ccrs ax = plt.axes(projection=ccrs.PlateCarree()) ax.coastlines(resolution='50m') ax.set_extent([-12, 3, 49, 60])
Change the projection to Mercator import matplotlib.pyplot as plt import
cartopy.crs as ccrs ax = plt.axes(projection=ccrs.GOOGLE_MERCATOR) ax.coastlines(resolution='50m') ax.set_extent([-12, 3, 49, 60])
None
To add boundaries, we need shapefiles • A format for
storing the location, shape, and attributes of geographic features • Found online (we used ONS - bit.ly/ons-boundaries) • Stored as a set of related files (don’t just download the .shp file)
Let’s add regional boundaries import matplotlib.pyplot as plt import cartopy.crs
as ccrs from cartopy.io.shapereader import Reader from cartopy.feature import ShapelyFeature file = '../uk_regions/uk_regions.shp' ax = plt.axes(projection=ccrs.GOOGLE_MERCATOR) ax.coastlines(resolution='50m') ax.set_extent([-12, 3, 49, 60])
Let’s add regional boundaries import matplotlib.pyplot as plt import cartopy.crs
as ccrs from cartopy.io.shapereader import Reader from cartopy.feature import ShapelyFeature file = '../uk_regions/uk_regions.shp' ax = plt.axes(projection=ccrs.GOOGLE_MERCATOR) ax.coastlines(resolution='50m') ax.set_extent([-12, 3, 49, 60]) regions = ShapelyFeature(Reader(file).geometries(), ccrs.PlateCarree(), facecolor=‘grey') ax.add_feature(regions)
Merge data + region shapes {region.attributes['name_small']: region.geometry for region in
Reader(file).records()}
Plot the data ax = plt.axes(projection=ccrs.GOOGLE_MERCATOR) ax.coastlines(resolution='50m') ax.set_extent([-12, 3, 49,
60]) norm = matplotlib.colors.Normalize(vmin=-6, vmax=4) cmap = plt.cm.gray_r for i, row in df.iterrows(): region = ShapelyFeature(df['shape'][i], ccrs.PlateCarree(), facecolor= cmap(norm(df[‘dev’][i])), ) ax.add_feature(region)
Plot the data ax = plt.axes(projection=ccrs.GOOGLE_MERCATOR) ax.coastlines(resolution='50m') ax.set_extent([-12, 3, 49,
60]) norm = matplotlib.colors.Normalize(vmin=-6, vmax=4) cmap = plt.cm.gray_r for i, row in df.iterrows(): region = ShapelyFeature(df['shape'][i], ccrs.PlateCarree(), facecolor= cmap(norm(df[‘dev’][i])), ) ax.add_feature(region)
Plot the data ax = plt.axes(projection=ccrs.GOOGLE_MERCATOR) ax.coastlines(resolution='50m') ax.set_extent([-12, 3, 49,
60]) norm = matplotlib.colors.Normalize(vmin=-6, vmax=4) cmap = plt.cm.gray_r for i, row in df.iterrows(): region = ShapelyFeature(df['shape'][i], ccrs.PlateCarree(), facecolor= cmap(norm(df[‘dev’][i])), ) ax.add_feature(region)
Change the colour scheme
Add a colorbar
Au revoir, France!
We’re looking for a data engineer!
[email protected]