mpld3 显示的工具栏通常位于屏幕的右下角。我希望它位于屏幕的右上角。似乎可以找到控制工具栏位置的代码here https://github.com/jakevdp/mpld3/blob/cec043807d18d788221455f1933f2cc7099f794e/src/toolbar/toolbar.js#L55.
我想知道如何使用 Javascript 选择工具栏对象,以便我可以更改它的位置。理想情况下,Javascript 代码是某些自定义 mpld3 插件的属性。
这是一个简单的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"}
您可以在以下位置看到它的实际效果这里有一个笔记本 http://nbviewer.ipython.org/gist/aflaxman/e8000969652f6a967279.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)