Playing with trying to get hovering tool time with density plots.


In [102]:
import matplotlib.pyplot as plt
%matplotlib inline
import mpld3
import numpy as np
import pandas as pd

In [103]:
# Create test dataset
dat = pd.DataFrame({'one': np.random.normal(size=1000), 
                    'two': np.random.normal(loc=0.1, size=1000), 
                    'three': np.random.normal(loc=-0.1, size=1000)
                    })

dat.head(3)


Out[103]:
one three two
0 0.618650 -0.299517 -0.408002
1 -0.729034 0.676223 -0.560406
2 -0.290377 1.211442 0.669659

In [104]:
dat.plot(kind='kde')


Out[104]:
<matplotlib.axes.AxesSubplot at 0x7f5f0bc19c50>

In [112]:
fig, ax = plt.subplots(figsize=(8,8))
density = dat.plot(kind='kde', ax=ax)
labels = [x.get_label() for x in density.get_lines()]

t1 = mpld3.plugins.LineLabelTooltip(density.get_lines()[0], labels[0])
t2 = mpld3.plugins.LineLabelTooltip(density.get_lines()[1], labels[1])
t3 = mpld3.plugins.LineLabelTooltip(density.get_lines()[2], labels[2])

mpld3.plugins.connect(fig, t1, t2, t3)
mpld3.display()


Out[112]:

In [ ]: