geoplot
¶This document shows how one can leverage the recent release of palettable
to make choropleths using the ever famous Viridis palette.
%matplotlib inline
import bokeh as bk
import palettable as pltt
import geopandas as gpd
import pysal as ps
from pysal.contrib import pdio
from pysal.contrib.geotable.utils import to_df, to_gdf
from pysal.contrib.viz.mapping import geoplot
pl = pltt.matplotlib.Viridis_10
bk.plotting.output_notebook()
Let's load up the US counties, and we will use homicide rates in 1990 (HR90
) as an example. As a bonus, this is also an example about how you can read data in geopandas
, reproject it, and push it over to PySAL
's new geotable
!
gdf = gpd.read_file(ps.examples.get_path('NAT.shp'))
gdf.crs = {'init' :'epsg:4326'}
gdf = gdf.to_crs(epsg=3083)
gdb = to_df(gdf)
Good to go! Thanks to geoplot
, this means you can plot with equal ease using both backends to matplotlib
and bokeh
.
matplotlib
geoplot(gdb, 'HR90', palette=pl, k=10)
bokeh
geoplot(gdb, 'HR90', palette=pl, k=10, backend='bk')
/home/dani/anaconda/envs/gds3/lib/python3.5/site-packages/bokeh/models/sources.py:81: BokehUserWarning: ColumnDataSource's columns must be of the same length lambda: warnings.warn("ColumnDataSource's columns must be of the same length", BokehUserWarning)) /home/dani/anaconda/envs/gds3/lib/python3.5/site-packages/bokeh/models/sources.py:81: BokehUserWarning: ColumnDataSource's columns must be of the same length lambda: warnings.warn("ColumnDataSource's columns must be of the same length", BokehUserWarning)) /home/dani/anaconda/envs/gds3/lib/python3.5/site-packages/bokeh/models/sources.py:81: BokehUserWarning: ColumnDataSource's columns must be of the same length lambda: warnings.warn("ColumnDataSource's columns must be of the same length", BokehUserWarning)) /home/dani/anaconda/envs/gds3/lib/python3.5/site-packages/bokeh/models/sources.py:81: BokehUserWarning: ColumnDataSource's columns must be of the same length lambda: warnings.warn("ColumnDataSource's columns must be of the same length", BokehUserWarning))