Protoyping choropleth classification schemes from PySAL for use with GeoPandas

Under the hood, if PySAL is not available or if an unsupported classification scheme is specified, the choropleth classification would fall back to GeoPandas defaults.


In [9]:
import geopandas as gp

In [10]:
# we use PySAL for loading a test shapefile
# replace this cell if you have a local shapefile and want to use GeoPandas readers
import pysal as ps 
pth = ps.examples.get_path("columbus.shp")
tracts = gp.GeoDataFrame.from_file(pth)

In [11]:
tracts.plot(column='CRIME', scheme='QUANTILES', k=3, colormap='OrRd')


Out[11]:
<matplotlib.axes.AxesSubplot at 0x10cedbed0>

In [12]:
tracts.plot(column='CRIME', scheme='Unrecognized', k=3, colormap='OrRd')


Unrecognized scheme:  Unrecognized
Using Quantiles instead
Out[12]:
<matplotlib.axes.AxesSubplot at 0x10f177290>

In [12]:


In [13]:
tracts.plot(column='CRIME', scheme='QUANTILES', k=1, colormap='OrRd')


Invalid k:  1
2<=k<=9, setting k=5 (default)
Out[13]:
<matplotlib.axes.AxesSubplot at 0x10f4bca90>

In [14]:
tracts.plot(column='CRIME', scheme='fisher_jenks', k=8, colormap='OrRd')


Out[14]:
<matplotlib.axes.AxesSubplot at 0x10fb36250>

In [15]:
tracts.plot(column='CRIME', scheme='equal_interval', k=7, colormap='OrRd')


Out[15]:
<matplotlib.axes.AxesSubplot at 0x10fd88790>

In [16]:
tracts.plot(column='CRIME', scheme='equal_interval', k=12, colormap='OrRd')


Invalid k:  12
2<=k<=9, setting k=5 (default)
Out[16]:
<matplotlib.axes.AxesSubplot at 0x10fd9bc90>

Notes

This is only using a subset of the classifiers in PySAL. specifically those that take only an attribute and a value of k as an argument. This simplifies the number of new default parameters that would be required in GeoPandas.DataFrame.plot().

It is of course possible to add other classifiers with the cost of additional kw args.


In [ ]: