#!/usr/bin/env python # coding: utf-8 # # Plotting with Viridis in PySAL's `geoplot` # # * [Dani Arribas-Bel](http://darribas.org) [[@darribas](http://twitter.com/darribas)] # # This document shows how one can leverage the recent release of [`palettable`](https://github.com/jiffyclub/palettable/releases/tag/v3.0.0) to make choropleths using the [ever famous Viridis](https://www.youtube.com/watch?v=xAoljeRJ3lU) palette. # In[1]: get_ipython().run_line_magic('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`! # In[2]: 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` # In[3]: geoplot(gdb, 'HR90', palette=pl, k=10) # * `bokeh` # In[4]: geoplot(gdb, 'HR90', palette=pl, k=10, backend='bk')