In [ ]:
import pandas as pd
from bokeh._legacy_charts import HeatMap, output_notebook, show
from bokeh.palettes import Blues9 as palette
palette = palette[::-1]
from bokeh.sampledata.unemployment1948 import data
In [ ]:
output_notebook()
In [ ]:
df = data[data.columns[:-1]]
df2 = df.set_index(df[df.columns[0]].astype(str))
df2.drop(df.columns[0], axis=1, inplace=True)
df3 = df2.transpose()
In [ ]:
hm = HeatMap(
df3, palette=palette, xlabel='Years since 1948', ylabel='Months',
title="Unemployment, pandas input", height=400, width=1000)
show(hm)
In [ ]:
hm_data = df3.values.T
hm = HeatMap(
hm_data, palette=palette, xlabel='Years since 1948', ylabel='Months',
title="Unemployment, array input", height=400, width=1000)
show(hm)
In [ ]:
simple_df = pd.DataFrame(
{'apples':[4,5,8,12,4], 'pears':[6,5,4,8,7], 'bananas':[1,2,4,8,12]},
index=['2009', '2010', '2011', '2012', '2013']
)
hm = HeatMap(
simple_df, palette=palette, title="Fruit comsumption per year", height=300, width=500)
show(hm)
In [ ]:
try:
from blaze import Data
simple_b = Data(simple_df)
hm = HeatMap(simple_b, palette=palette, title="Fruit comsumption per year", notebook=True, height=400, width=1000)
show(hm)
except ImportError:
# seems that blaze is not installed
pass
In [ ]: