mpld3显示工具栏通常位于屏幕右下角。我希望它在屏幕的右上角。似乎控制工具栏位置的代码可以定位为这里。
我想知道如何使用Javascript选择工具栏对象,以便更改它的位置。理想情况下,Javascript代码是一些自定义mpld3插件的属性。
发布于 2014-10-27 18:45:06
下面是一个简单的mpld3插件,可以将工具栏移动到图形的顶部:
class TopToolbar(plugins.PluginBase):
"""Plugin for moving toolbar to top of figure"""
JAVASCRIPT = """
mpld3.register_plugin("toptoolbar", TopToolbar);
TopToolbar.prototype = Object.create(mpld3.Plugin.prototype);
TopToolbar.prototype.constructor = TopToolbar;
function TopToolbar(fig, props){
mpld3.Plugin.call(this, fig, props);
};
TopToolbar.prototype.draw = function(){
// the toolbar svg doesn't exist
// yet, so first draw it
this.fig.toolbar.draw();
// then change the y position to be
// at the top of the figure
this.fig.toolbar.toolbar.attr("y", 2);
// then remove the draw function,
// so that it is not called again
this.fig.toolbar.draw = function() {}
}
"""
def __init__(self):
self.dict_ = {"type": "toptoolbar"}您可以在这里有本笔记本中看到它的作用。
https://stackoverflow.com/questions/26593759
复制相似问题