Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Plotting choropleth maps with Cartopy @ PyData ...
Search
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
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
360
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.9k
Flow は今どうなっているか
mizdra
PRO
0
670
初めての模倣学習とVLA
natsutan
0
140
今さら聞けない .NET CLI
htkym
0
210
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
170
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
220
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
19k
プロポーザルを書いてもらう
pvcresin
0
570
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.6k
リアルな遅延を測る仕様
kota_yata
1
120
Oxlintはいいぞ(続)
yug1224
1
330
Featured
See All Featured
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
420
A Soul's Torment
seathinner
6
3.5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Paper Plane (Part 1)
katiecoart
PRO
1
10k
Mobile First: as difficult as doing things right
swwweet
225
10k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Scaling GitHub
holman
464
140k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
390
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
A Tale of Four Properties
chriscoyier
163
24k
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]