In [ ]:
from bokeh.charts import HeatMap, bins, output_notebook, show, vplot
from bokeh.sampledata.autompg import autompg as df
from bokeh.sampledata.unemployment1948 import data
from bokeh.palettes import RdYlGn6, RdYlGn9
import pandas as pd
In [ ]:
output_notebook()
In [ ]:
df.head()
In [ ]:
hm = HeatMap(df, x=bins('mpg'), y=bins('displ'))
show(hm)
In [ ]:
hm = HeatMap(df, x=bins('mpg'), y=bins('displ'), values='cyl', stat='mean')
show(hm)
In [ ]:
hm = HeatMap(df, x=bins('mpg'), y=bins('displ', bins=15),
values='cyl', stat='mean')
show(hm)
In [ ]:
hm = HeatMap(df, x=bins('mpg'), y='cyl', values='displ', stat='mean')
show(hm)
In [ ]:
hm = HeatMap(df, y=bins('displ'), x=bins('mpg'), values='cyl', stat='mean',
spacing_ratio=0.9)
show(hm)
In [ ]:
hm = HeatMap(df, x=bins('mpg'), y=bins('displ'), stat='mean', values='cyl',
palette=RdYlGn6)
show(hm)
In [ ]:
hm = HeatMap(df, x=bins('mpg'), y=bins('displ'), stat='mean', values='cyl',
palette=RdYlGn9)
show(hm)
In [ ]:
hm = HeatMap(df, x=bins('mpg'), y=bins('displ'), values='cyl',
stat='mean', legend='top_right')
show(hm)
In [ ]:
fruits = {'fruit': ['apples', 'apples', 'apples', 'apples', 'apples',
'pears', 'pears', 'pears', 'pears', 'pears',
'bananas', 'bananas', 'bananas', 'bananas', 'bananas'],
'fruit_count': [4, 5, 8, 12, 4, 6, 5, 4, 8, 7, 1, 2, 4, 8, 12],
'year': [2009, 2010, 2011, 2012, 2013, 2009, 2010, 2011, 2012, 2013, 2009, 2010,
2011, 2012, 2013]}
fruits['year'] = [str(yr) for yr in fruits['year']]
fruits_df = pd.DataFrame(fruits)
fruits_df.head()
In [ ]:
hm = HeatMap(fruits, y='year', x='fruit', values='fruit_count', stat=None)
show(hm)
In [ ]:
unempl_data = data.copy()
unempl_data.head()
In [ ]:
# Remove the annual column if we don't want to show the total
del unempl_data['Annual']
# Convert numerical year to strings
unempl_data['Year'] = unempl_data['Year'].astype(str)
# de-pivot all columns, except for Year, into two columns.
# One column will have the values and the second will have the labels
unempl = pd.melt(unempl_data, var_name='Month', value_name='Unemployment', id_vars=['Year'])
In [ ]:
unempl.head()
In [ ]:
hm = HeatMap(unempl, x='Year', y='Month', values='Unemployment', stat=None,
sort_dim={'x': False}, height=200, responsive=True)
show(hm)
In [ ]: