Python 博克的多个地块
我有一个简单的bokeh布局,带有文本输入和按钮。单击按钮时,根据textinput.value,需要创建两个绘图 图1是networkx有向图,图2是价格的时间序列。以下是我尝试过的:Python 博克的多个地块,python,bokeh,Python,Bokeh,我有一个简单的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)
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图形添加到绘图中 简短的回答是“不”。或者至少,不是以你正在尝试的方式。Bokeh布局只能包含其他Bokeh对象,例如Bokeh库中的绘图、gmap绘图、数据表和小部件。Bokeh对networkx输出一无所知。Bokeh无法将其直接放入自己的布局中。从Bokeh0.12.6
开始,您有两个选项:
- 将networkx输出转换为真实的Bokeh图,请参见以下示例:
- 将Bokeh输出和networkx输出(PNG?)嵌入到Jinja HTML模板中,请参见 有关如何在HTML页面中嵌入Bokeh绘图的详细信息
请注意,对于
0.12.7
,将有更好的支持直接传递图形/网络数据,请参阅此打开的PR: