PySAL
and cartopy
: London boroughs, one by one¶This short example shows how one can easily use cartopy
to beautifully plot polygons from PySAL
. Read your data with PySAL
, convert them to matplotlib
with its viz
module and set the right projection and other geo goodies with cartopy
.
This notebook (and the data required to run it), are hosted as a gist
on this link.
%matplotlib inline
import matplotlib.pyplot as plt
import pysal as ps
import numpy as np
from pysal.contrib.viz import mapping as maps
import cartopy.io.img_tiles as cimgt
import cartopy.crs as ccrs
London borough data from Robin Lovelace's tutorial on R (link). The shapefile LondonBoroughs
is reprojected to lon/lat and renamed boroughs
. For convenience, the shapefile is attached to the gist where this notebook is hosted.
shp = ps.open('boroughs.shp')
bg = cimgt.OSM()
extent = [shp.bbox[0], shp.bbox[2], shp.bbox[1], shp.bbox[3]]
boros = maps.map_poly_shp(shp)
boros.set_transform(ccrs.Geodetic())
boros.set_facecolor('none')
f = plt.figure(figsize=(10, 8))
ax = plt.axes(projection=bg.crs)
ax.set_extent(extent)
ax.add_image(bg, 11)
ax.add_collection(boros)
f.suptitle('London boroughs, all together')
plt.show()