Python networkx 筆記
NetworkX 用於建立網絡模型、繪製網路圖、分析網絡結構等等的算法以及一些基本的繪圖工具。
創建 Graph
networkx 有四種圖,分別為無向圖、有向圖、多重邊無向圖、多重邊有向圖。
1 | import networkx as nx |
添加節點
1 | G.add_node('A') |
添加邊與權重
1 | G.add_edge('A', 'D', weight=0.8) |
刪除
1 | # 刪除節點 |
另外也可以從 DataFrame 載入
1 | import pandas as pd |
繪圖 nx.draw()
需要使用 matplotlib
1 | import matplotlib.pyplot as plt |
詳解 nx.draw()
1 | G: networkx 圖 |
pos
1 | nx.random_layout:隨機分佈 |
範例:
1 | plt.figure(1, figsize=(8,8)) |
- Post Title: Python networkx 筆記
- Post Author: Samir Liu
- Post Link: https://smiliu.xyz/posts/54898.html
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.