!date
Thu Apr 30 13:55:05 PDT 2015
"""Plot to test stopping toolbar from moving"""
import matplotlib.pyplot as plt
import numpy as np
import mpld3, mpld3.plugins as plugins
%matplotlib inline
mpld3.enable_notebook()
class TweakToolbar(plugins.PluginBase):
"""Plugin for changing toolbar"""
JAVASCRIPT = """
mpld3.register_plugin("tweaktoolbar", TweakToolbar);
TweakToolbar.prototype = Object.create(mpld3.Plugin.prototype);
TweakToolbar.prototype.constructor = TweakToolbar;
function TweakToolbar(fig, props){
mpld3.Plugin.call(this, fig, props);
};
TweakToolbar.prototype.draw = function(){
// the toolbar svg doesn't exist
// yet, so first draw it
this.fig.toolbar.draw();
// then change the toolbar as desired
// show toolbar
this.fig.toolbar.buttonsobj.transition(750).attr("y", 0);
// remove event triggers
this.fig.canvas
.on("mouseenter", null)
.on("mouseleave", null)
.on("touchenter", null)
.on("touchstart", null);
// then remove the draw function,
// so that it is not called again
this.fig.toolbar.draw = function() {}
}
"""
def __init__(self):
self.dict_ = {"type": "tweaktoolbar"}
plt.plot([3,1,4,1,5,9], 'ks-')
plugins.connect(plt.gcf(), TweakToolbar())