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]:
In [104]:
dat.plot(kind='kde')
Out[104]:
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 [ ]: