I am attempting to build a network graph using NetworkX and Bokeh. I am using the NetworkX from_pandas_edgelist
function to add data for the graph. I would like to color the node of the graph based on the column in the initial data input.
The relation
DataFrame is as follows:
company client
Google AT&T
Google Cisco
Amazon Facebook
Amazon Snap
Amazon Microsoft
Apple Intel
Apple IBM
Apple Visa
The above snippet is only a portion of the DataFrame.
I would like all of the nodes from company
to return in a different color to client
.
The code below produces a network graph where all nodes are the same color.
G=nx.from_pandas_edgelist(relation, 'company', 'client')
# Show with Bokeh
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, BoxZoomTool(), ResetTool())
graph_renderer = from_networkx(G, nx.spring_layout, scale=1, center=(0, 0))
graph_renderer.node_renderer.glyph = Circle(size=20)
graph_renderer.edge_renderer.glyph = MultiLine(line_color="red", line_alpha=0.8, line_width=1)
plot.renderers.append(graph_renderer)
output_file("interactive_graphs.html")
show(plot)
Any assistance anyone could provide would be greatly appreciated.