2017-06-26 25 views
0

私は、テキスト入力とボタン付きの単純なボケレイアウトでした。ボタンをクリックすると、textinput.valueに応じて、2つのプロットを作成する必要があります。Bokehの複数のプロット

プロット1はネットワークxディグラグラフであり、プロット2は価格の時系列です。ここで私が試したことは次のとおりです。

ask_input = TextInput(placeholder="Search", width = 500, height=100) 
ask_button = Button(label="GET", width = 100, height=50) 
ask_button.on_click(addPlots) 

layout = layout([[widgetbox(ask_input, ask_button)]]) 
curdoc().add_root(layout) 

def addPlots():  
    p1=buildGraph() 
    p2=buildPlot() 
    layout.children[-1].children.append(row([p1],[p2])) 

def buildGraph(): 
    for i in range(len(graph_matrix)): 
      client_graph.add_edge(green_nodes[i], orange_nodes[i], weight=weights[i]) 

    node_size=5000 
    pos=nx.spring_layout(client_graph)  

    node_colors = ['green' if node in green_nodes.unique() else 'orange' 
      for node in client_graph.nodes()] 
    nx.draw_networkx_edges(client_graph, pos, arrows=True) 

    nx.draw_networkx_nodes(client_graph, pos,with_labels=True, arrows = True, node_size=node_size, node_color=node_colors) 
    nx.draw_networkx_labels(client_graph, pos, font_size=15,font_family='CONSOLAS', with_labels=True, arrows=True) 
    #this is where there maybe a disconnect between the graph and the plot 
    fig = figure(title='Connections') 
    return fig 

def buildPlot(): 
    fig2=stock_df.plot('adj_close',data=stock_df) #against a DateTimeIndex 
    return fig2 

エラーは、LayoutDOM以外のオブジェクトを行に挿入できないということです。グラフ/プロットを図の右​​側に追加していないことを確認してください。 networkxグラフをプロットに追加できますか?

答えて

1

短い答えは「いいえ」です。または、少なくとも、あなたが試みている方法ではありません。 Bokehレイアウトは他のBokehオブジェクトのみを含むことができます。 Bokehライブラリの一部であるプロット、gmapプロット、データテーブル、ウィジェットなどがあります。 Bokehはnetworkxの出力について何も知らない。 Bokehが独自のレイアウトの1つに直接入れることはできません。ボケ0.12.6のとして、あなたは、オプションのカップルがあります

  • をこの例を参照して、実際のボケのプロットにnetworkx出力を変換します

    https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/graphs.py

  • 埋め込みボケ出力とnetworkx Jinja HTMLテンプレートの出力(PNG?)あなたはより具体的otのそのハードをやろうとしているものの、より大きな文脈のないHTMLページ

でボケプロットを埋め込むか、どのアプローチと言う方法の詳細は、

http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html

より良いかもしれない。


0.12.7のために、このオープンPRを参照して、直接グラフ/ネットワークデータを渡すためのより良いサポートがあることに注意してください:

https://github.com/bokeh/bokeh/pull/6544

関連する問題