Texas choropleth example

URL: http://bokeh.pydata.org/en/latest/docs/gallery/texas.html

Most examples work across multiple plotting backends, this example is also available for:

In [1]:
import numpy as np
import holoviews as hv
hv.extension('matplotlib')
%output fig='svg'

Declaring data

In [2]:
from bokeh.sampledata.us_counties import data as counties
from bokeh.sampledata.unemployment import data as unemployment

counties = {
    code: county for code, county in counties.items() if county["state"] == "tx"
}

county_xs = [county["lons"] for county in counties.values()]
county_ys = [county["lats"] for county in counties.values()]

county_names = [county['name'] for county in counties.values()]
county_rates = [unemployment[county_id] for county_id in counties]

county_polys = {name: hv.Polygons((xs, ys), level=rate, vdims=['Unemployment'])
                for name, xs, ys, rate in zip(county_names, county_xs, county_ys, county_rates)}

choropleth = hv.NdOverlay(county_polys, kdims=['County'])

Plot

In [3]:
plot_opts = dict(logz=True, xaxis=None, yaxis=None,
                 show_grid=False, show_frame=False, fig_size=200, bgcolor='white')
style = dict(edgecolor='white')

choropleth({'Polygons': {'style': style, 'plot': plot_opts}})
Out[3]: