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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
230
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.4k
AIで効率化できた業務・日常
ochtum
0
140
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
580
Claspは野良GASの夢をみるか
takter00
0
190
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
330
CSC307 Lecture 17
javiergs
PRO
0
320
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
170
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.3k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
760
Creating Composable Callables in Contemporary C++
rollbear
0
130
Featured
See All Featured
Building AI with AI
inesmontani
PRO
1
1.1k
Optimizing for Happiness
mojombo
378
71k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
180
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
330
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Building an army of robots
kneath
306
46k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
For a Future-Friendly Web
brad_frost
183
10k
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]