Debian Codegraph @

examples/with-descartes-functional.py

raw
1 # Making maps with reduce()
2
3 from matplotlib import pyplot
4 from descartes import PolygonPatch
5 import fiona
6
7 BLUE = '#6699cc'
8
9 def render(fig, rec):
10 """Given matplotlib axes and a record, adds the record as a patch
11 and returns the axes so that reduce() can accumulate more
12 patches."""
13 fig.gca().add_patch(
14 PolygonPatch(rec['geometry'], fc=BLUE, ec=BLUE, alpha=0.5, zorder=2))
15 return fig
16
17 with fiona.open('docs/data/test_uk.shp', 'r') as source:
18 fig = reduce(render, source, pyplot.figure(figsize=(8, 8)))
19 fig.gca().autoscale(tight=False)
20 fig.savefig('with-descartes-functional.png')
21