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
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
JRuby: Past, Present, and Future
headius
0
140
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
300
App Intentsのビルドプロセスを支える技術
kntkymt
0
400
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
440
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
190
wkhtmltopdfの次どうするか問題2026
willnet
2
1.5k
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
7.5k
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
150
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
280
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
350
新卒PdEのリアル
ryu1013
1
500
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
310
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
360
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
So, you think you're a good person
axbom
PRO
2
2.2k
Mind Mapping
helmedeiros
1
360
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
240
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
910
Accessibility Awareness
sabderemane
1
210
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Site-Speed That Sticks
csswizardry
13
1.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
680
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]