[英]Multiple Plots in Bokeh
我有一個帶有文本輸入和按鈕的簡單散景布局。 單擊按鈕時,根據 textinput.value,需要創建兩個圖。
圖 1 是 networkx 有向圖,圖 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 圖添加到繪圖中嗎?
最簡潔的答案是不”。 或者至少,不是你嘗試的方式。 散景布局只能包含其他散景對象,例如作為散景庫一部分的繪圖、gmap 繪圖、數據表和小部件。 Bokeh 對 networkx 輸出一無所知。 這不是 Bokeh 可以直接放入其自己的布局之一的東西。 從 Bokeh 0.12.6
您有幾個選擇:
將 networkx 輸出轉換為真實的散景圖,請參閱此示例:
https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/graphs.py
在 Jinja HTML 模板中嵌入 Bokeh 輸出和 networkx 輸出(PNG?),參見例如
http://docs.bokeh.org/en/latest/docs/user_guide/embed.html
有關如何在 HTML 頁面中嵌入散景圖的詳細信息
沒有更多關於您正在努力做的事情的更大背景,或者更具體,或者說哪種方法可能更好。
請注意, 0.12.7
將更好地支持直接傳遞圖形/網絡數據,請參閱此公開 PR:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.