!date import numpy as np, pandas as pd, pymc as pm, matplotlib.pyplot as plt, seaborn as sns %matplotlib inline sns.set_context('paper') sns.set_style('darkgrid') import mpld3 mpld3.enable_notebook() def create_plot(): fig, ax = plt.subplots(figsize=(12,4)) x = np.linspace(0, 10, 100) l1 = ax.plot(x, np.sin(x), label='sin', lw=3, alpha=1) l2 = ax.plot(x, np.cos(x), label='cos', lw=3, alpha=1) l3 = ax.plot(x[::5], 0.5 * np.sin(x[::5] + 2), 'ob', label='dots', alpha=1) labels = ['sin', 'cos', 'dots'] interactive_legend = mpld3.plugins.InteractiveLegendPlugin([l1, l2, l3], labels, start_visible=[1, 0, True]) mpld3.plugins.connect(fig, interactive_legend) ax.set_title("Interactive legend test", size=20) plt.subplots_adjust(right=.5) create_plot()