In [12]:
import numpy as np
import matplotlib.pyplot as plt
mpld3.enable_notebook()
In [3]:
np.random.seed(0)
plt.plot(np.random.rand(10));
In [1]:
import mpld3
from mpld3 import plugins
#%matplotlib inline
#mpld3.enable_notebook()
class HelloWorld(plugins.PluginBase): # inherit from PluginBase
"""Hello World plugin"""
JAVASCRIPT = """
mpld3.register_plugin("helloworld", HelloWorld);
HelloWorld.prototype = Object.create(mpld3.Plugin.prototype);
HelloWorld.prototype.constructor = HelloWorld;
function HelloWorld(fig, props){
mpld3.Plugin.call(this, fig, props);
};
HelloWorld.prototype.draw = function(){
this.fig.canvas.append("text")
.text("hello world")
.style("font-size", 72)
.style("opacity", 0.3)
.style("text-anchor", "middle")
.attr("x", this.fig.width / 2)
.attr("y", this.fig.height / 2)
}
"""
def __init__(self):
self.dict_ = {"type": "helloworld"}
fig, ax = plt.subplots();
plugins.connect(fig, HelloWorld())
In [2]:
from IPython.display import HTML
MyHTML=mpld3.fig_to_html(fig, template_type="simple")
HTML(MyHTML)
Out[2]:
In [ ]: