2014-10-27 67 views
3

mpld3顯示的工具欄通常位於屏幕的右下角。我希望它位於屏幕的右上角。看起來好像控制工具欄位置的代碼可以位於herempld3:如何使用插件更改工具欄的位置?

我想知道如何選擇使用Javascript的工具欄對象,以便我可以改變它的位置。該Javascript代碼理想情況下是一些自定義mpld3插件的屬性。

回答

4

下面是一個簡單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"} 

您可以在a notebook here看到它的行動。

+0

這工作完美。非常感謝。 – mattcart 2014-10-27 18:53:34