#%run talktools %matplotlib inline import matplotlib.pyplot as plt import numpy as np from IPython.display import HTML # CSS formatting from IPython.display import HTML HTML(""" """) x, y = np.random.normal(0, 1, [2, 100]) c, s = 800 * np.random.random([2, 100]) fig = plt.figure() points = plt.scatter(x, y, c=c, s=s, alpha=0.3) plt.grid(color="lightgray"); import mpld3 mpld3.enable_notebook() fig mpld3.fig_to_dict(fig) from mpld3 import plugins labels = ['Point {0}'.format(i) for i in range(100)] tooltips = plugins.PointLabelTooltip(points, labels) plugins.connect(fig, tooltips) fig from sklearn.datasets import load_iris iris = load_iris() # dither the data for clearer plotting iris.data += 0.1 * np.random.random(iris.data.shape) fig, ax = plt.subplots(4, 4, sharex="col", sharey="row", figsize=(8, 8)) fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95, hspace=0.1, wspace=0.1) for i in range(4): for j in range(4): points = ax[3 - i, j].scatter(iris.data[:, j], iris.data[:, i], c=iris.target, s=40, alpha=0.6) # remove tick labels for axi in ax.flat: for axis in [axi.xaxis, axi.yaxis]: axis.set_major_formatter(plt.NullFormatter()) # Here we connect the linked brush plugin plugins.connect(fig, plugins.LinkedBrush(points)) from mpld3 import plugins, utils class HighlightLines(plugins.PluginBase): """A plugin to highlight lines on hover""" JAVASCRIPT = """ mpld3.register_plugin("linehighlight", LineHighlightPlugin); LineHighlightPlugin.prototype = Object.create(mpld3.Plugin.prototype); LineHighlightPlugin.prototype.constructor = LineHighlightPlugin; LineHighlightPlugin.prototype.requiredProps = ["line_ids"]; LineHighlightPlugin.prototype.defaultProps = {alpha_bg:0.3, alpha_fg:1.0} function LineHighlightPlugin(fig, props){ mpld3.Plugin.call(this, fig, props); }; LineHighlightPlugin.prototype.draw = function(){ for(var i=0; i