In [1]:
!date
Mon Mar 17 08:01:35 PDT 2014
In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np, pandas as pd
import mpld3
mpld3.enable_notebook(d3_url='/files/mpld3/js/d3.v3.min.js', mpld3_url='/files/mpld3/js/mpld3.v0.2git.js')
In [3]:
css = """
table
{
border-collapse: collapse;
}
th
{
color: #ffffff;
background-color: #000000;
}
td
{
background-color: #cccccc;
}
table, th, td
{
font-family:Arial, Helvetica, sans-serif;
border: 1px solid black;
text-align: right;
}
"""
In [4]:
# table of details-on-demand

df = pd.DataFrame()
for i in range(5):
    for j in range(10):
        df = df.append(dict(row=i, col=j, val=np.random.rand()), ignore_index=True)

df['X_1'] = np.random.randint(low=0, high=3, size=50)
df['X_2'] = np.random.randint(low=10, high=20, size=50)

A = np.array(df.pivot('row', 'col', 'val'))
fig = plt.figure(figsize=(9,6))
ax = fig.gca()
ax.set_aspect('equal', 'box')
mesh = ax.pcolormesh(A)
ax.invert_yaxis()

labels = [df_g.T.to_html() for (i,j),df_g in df.groupby(['row', 'col'])]
fig.plugins = [mpld3.plugins.PointHTMLTooltip(mesh, labels, css=css)]