Mapping using Pysal and Folium: Texas


In [12]:
import pysal as ps
import geopandas as gpd
import folium_mapping as fm
%matplotlib inline

Let's look at the columns that we're going to map.


In [9]:
df = gpd.read_file('./example.json')

In [13]:
df.HR90.hist()


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f03fd71bba8>

To use the folium mapper, you pass the the geodataframe, a unique key for the geometries, & the attribute to be mapped:


In [15]:
fm.choropleth_map(df, key='FIPS', attribute='HR90')


Out[15]:

There are arguments to change classification scheme:


In [18]:
fm.choropleth_map(ex, 'FIPS', 'HR90', classification = 'Equal Interval')


Out[18]:

Most PySAL classifiers are supprorted.

Base Map Type


In [19]:
fm.choropleth_map(ex, 'FIPS', 'HR90', 
                  classification = 'Jenks Caspall', 
                  tiles='Stamen Toner', save=True)


Out[19]:

We support the entire range of builtin basemap types in Folium, but custom tilesets from MapBox are not supported yet.

Color Scheme


In [20]:
fm.choropleth_map(ex, 'FIPS', 'HR80', 
                  classification = 'Jenks Caspall', 
                  tiles='Stamen Toner', fill_color = 'PuBuGn', save=True)


Out[20]:

All color schemes are Color Brewer and simply pass through to Folium on execution.

Class numbers


In [25]:
fm.choropleth_map('./example.json', 'FIPS', 'HR80', 
                  classification = 'Jenks Caspall', 
                  classes=3, tiles='Stamen Toner', 
                  fill_color='PuBuGn',save=True)


Out[25]:

Standardization


In [27]:
fm.choropleth_map(ex, 'FIPS', 'HR90', 
                  classification = 'Quantiles', 
                  std='HR80' , tiles='Stamen Toner', 
                  fill_color='PuBuGn',save=True)


/home/ljw/anaconda3/envs/ana/lib/python3.6/site-packages/pysal/esda/mapclassify.py:267: RuntimeWarning: invalid value encountered in greater
  binIds += (x > l) * (x <= r) * k
/home/ljw/anaconda3/envs/ana/lib/python3.6/site-packages/pysal/esda/mapclassify.py:267: RuntimeWarning: invalid value encountered in less_equal
  binIds += (x > l) * (x <= r) * k
/home/ljw/anaconda3/envs/ana/lib/python3.6/site-packages/numpy/lib/function_base.py:4016: RuntimeWarning: Invalid value encountered in median
  r = func(a, **kwargs)
Out[27]: