import json import numpy as np import matplotlib.pyplot as plt import mpld3 from mpld3 import plugins, utils class VoronoiHighlightLines(plugins.PluginBase): """A plugin to highlight lines on hover see also http://bl.ocks.org/mbostock/8033015 """ JAVASCRIPT = """ mpld3.register_plugin("voronoi_highlightlines", VoronoiHighlightLines); VoronoiHighlightLines.prototype = Object.create(mpld3.Plugin.prototype); VoronoiHighlightLines.prototype.constructor = VoronoiHighlightLines; VoronoiHighlightLines.prototype.requiredProps = ["line_ids"]; VoronoiHighlightLines.prototype.defaultProps = {alpha_bg:0.3, alpha_fg:1.0} function VoronoiHighlightLines(fig, props){ mpld3.Plugin.call(this, fig, props); }; VoronoiHighlightLines.prototype.draw = function(){ var alpha_fg = this.props.alpha_fg; var alpha_bg = this.props.alpha_bg; // get the data for the voronoi mesh data = new Array(); for(var i=0; i