`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.

In [20]:

```
%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
```

`LondonBoroughs`

is reprojected to lon/lat and renamed `boroughs`

. For convenience, the shapefile is attached to the gist where this notebook is hosted.

In [21]:

```
shp = ps.open('boroughs.shp')
bg = cimgt.OSM()
```

In [22]:

```
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()
```