旧的编辑后:
无法提供太多背景信息,因为我对bokeh并不十分熟悉,但是看起来您可以使用与我最初类似的方法,而不必通过“color_map”来执行绘制功能,而必须将数据粘贴在这里graph_renderer.node_renderer.data_source.data['colors']
无论如何,这似乎可以解决问题,祝您好运。
relation = pd.DataFrame({
"company":["Google", "Google", "Amazon", "Amazon", "Amazon",
"Apple", "Apple", "Apple"],
"client":["AT&T", "Cisco", "Facebook", "Snap", "Microsoft",
"Intel", "IBM", "Visa"]})
G=nx.from_pandas_edgelist(relation, 'company', 'client')
colors = []
for node in G:
if node in relation["client"].values:
colors.append("blue")
else: colors.append("green")
plot = Plot(plot_width=1000, plot_height=800,
x_range=Range1d(-1.1, 1.1), y_range=Range1d(-1.1, 1.1))
plot.title.text = "Company - Client Network"
node_hover_tool = HoverTool(tooltips=[("Company Name", "@index")])
plot.add_tools(node_hover_tool, @R_285_2419@ZoomTool(), ResetTool())
graph_renderer = from_networkx(G, nx.spring_layout, scale=1, center=(0, 0))
graph_renderer.node_renderer.data_source.data['colors'] = colors
graph_renderer.node_renderer.glyph = Circle(size=20, fill_color='colors')
graph_renderer.edge_renderer.glyph = MultiLine(line_color="red", line_alpha=0.8, line_width=1)
plot.renderers.append(graph_renderer)
output_file("boo.html")
show(plot)