본문 바로가기

Data Science & Analytics

[Library review] NetworkX 에 대해 알아보자

반응형

NetworkX library 에 대해 리뷰할 예정이다. 

 

 

1. draw_networkx

https://networkx.org/documentation/latest/reference/generated/networkx.drawing.nx_pylab.draw_networkx.html

 

draw_networkx — NetworkX 3.1rc1.dev0 documentation

draw_networkx draw_networkx(G, pos=None, arrows=None, with_labels=True, **kwds)[source] Draw the graph G using Matplotlib. Draw the graph with Matplotlib with options for node positions, labeling, titles, and many other drawing features. See draw() for sim

networkx.org

 

2. Networkx graphs from source-target dataframes

https://jonathansoma.com/lede/algorithms-2017/classes/networks/networkx-graphs-from-source-target-dataframe/

 

NetworkX Graphs from Source-Target DataFrame

This page is based on a Jupyter/IPython Notebook: download the original .ipynb Making networkx graphs from source-target DataFrames Imports/setup Let’s just get all of this out of the way up top. %matplotlib inline import pandas as pd import networkx as

jonathansoma.com

 

 

 

 

 

Reference 

https://stackoverflow.com/questions/25036843/how-to-determine-specific-color-and-size-of-chosen-nodes-in-networkx-graph-plot

 

How to determine specific color and size of chosen nodes in Networkx graph plot

I have the following code #!/usr/bin/python import sys import networkx as nx import matplotlib.pyplot as plt G = nx.Graph(); G.add_node('A') G.add_node('B') G.add_node('C') G.add_node('D') G.

stackoverflow.com

 

Before

output_graph
output_graph_matrix = nx.adjacency_matrix(output_graph).todense()
nx.draw_networkx(output_graph, font_size=10, font_color='r')
sns.heatmap(output_graph_matrix)

 

 

After

output_graph
output_graph_matrix = nx.adjacency_matrix(output_graph).todense()
nx.draw_spring(output_graph, nodelist=sorted(output_graph.nodes()), font_size=20, width=2,
                    node_size=[100, 100, 200, 300,200, 200, 200,200,200,200,200],
                    node_color=['g','r','b','g','r','b','g','r','b','g','r']
               )

 

반응형
LIST