我有一个简单的bokeh布局与文本输入和按钮。单击按钮时,取决于文本输入值,需要创建两个绘图。在
图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图形是否可以添加到绘图中?在
简短的回答是“不”。或者至少,不是你想的那样。Bokeh布局只能包含其他Bokeh对象,例如作为Bokeh库一部分的plots、gmap plots、data tables和widget。Bokeh对networkx输出一无所知。这不是Bokeh可以直接放在自己的布局中的东西。在Bokeh
0.12.6
你有几个选择:将networkx输出转换为真实的Bokeh图,请参见以下示例:
https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/graphs.py
嵌入Bokeh输出和networkx输出(PNG?)在Jinja HTML模板中,请参见
http://docs.bokeh.org/en/latest/docs/user_guide/embed.html
有关如何在HTML页面中嵌入Bokeh绘图的详细信息
如果没有更多关于你正在尝试做什么的更大背景,就很难更具体,或者说哪种方法可能更好。在
请注意,对于
0.12.7
将有更好的支持直接传递图形/网络数据,请参阅以下公开声明:https://github.com/bokeh/bokeh/pull/6544
相关问题 更多 >
编程相关推荐