Search
plot

Demonstrating plotting with geopandas

Note that this relies on a development branch of geopandas: https://github.com/sjsrey/geopandas/tree/legendkwds that is planned for submission to geopandas.

import libpysal 
import geopandas as gpd
import mapclassify as mc
columbus = gpd.read_file(libpysal.examples.get_path('columbus.shp'))
q5 = mc.Quantiles(columbus.CRIME, k=5)
q5
Quantiles             

   Interval      Count
----------------------
[ 0.18, 19.02] |    10
(19.02, 29.33] |    10
(29.33, 39.03] |     9
(39.03, 53.16] |    10
(53.16, 68.89] |    10
q5.plot(columbus)
(<Figure size 640x480 with 1 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7f156a7ec9e8>)
q5.plot(columbus, axis_on=False)
(<Figure size 432x288 with 1 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7f156a76d518>)
q5.plot(columbus, axis_on=False, cmap='Blues')
(<Figure size 432x288 with 1 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7f1562e60f98>)
f = q5.plot(columbus, axis_on=False, cmap='Blues')
f = q5.plot(columbus, axis_on=False, cmap='Blues', title='Columbus, OH')
f = q5.plot(columbus, axis_on=False, cmap='Blues', title='Columbus, OH', \
           legend=True)
f = q5.plot(columbus, axis_on=False, cmap='Blues', title='Columbus, OH', \
           legend=True, legend_kwds={'loc':'upper right'})
f = q5.plot(columbus, axis_on=False, cmap='Blues', title='Columbus, OH', \
           legend=True, legend_kwds={'loc':'upper left', 'title': 'Crime Rate'})
f = q5.plot(columbus, axis_on=False, cmap='Blues', title='Columbus, OH', \
           legend=True, legend_kwds={'loc':'upper left', 'title': 'Crime Rate'}, \
           file_name='crime.png')
f = q5.plot(columbus, axis_on=False, cmap='Blues', title='Columbus, OH', \
           legend=True, legend_kwds={'loc':'upper left', 'title': 'Crime Rate, 1988'}, \
           file_name='crime.png', border_color='green', border_width=2.0)

Legend Formatting

f = q5.plot(columbus, axis_on=False, cmap='Blues', title='Columbus, OH', \
           legend=True, legend_kwds={'loc':'upper left', 'title': 'Crime Rate, 1988', 
                                    'fmt':'{:.1f}'}, \
           file_name='crime.png', border_color='green', border_width=2.0)
f = q5.plot(columbus, axis_on=False, cmap='Blues', title='Columbus, OH', \
           legend=True, legend_kwds={'loc':'upper left', 'title': 'Crime Rate, 1988', 
                                    'fmt':'{:.0f}'}, \
           file_name='crime.png', border_color='green', border_width=2.0)