NetworkX 사용 방법

5534 단어 Python3networkx
NetworkX를 사용하는 방법입니다.
number01.py
#! /usr/bin/python
#
#   number01.py
#
#                       Apr/16/2019
# ------------------------------------------------------------------
import sys
import networkx as nx

# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")

G = nx.DiGraph()  # 有向グラフ (Directed Graph)

data_array = [1,2,3,4,5,6,7,8]

# 指定した閉路上の頂点と辺を追加
G.add_cycle(data_array)
#
nx.nx_agraph.view_pygraphviz(G, prog='fdp')
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------
실행 결과

태그 예 사용
label01.py
#! /usr/bin/python
#
#   label01.py
#
#                       Apr/16/2019
# ------------------------------------------------------------------
import sys
import networkx as nx
# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")

G = nx.DiGraph()  # 有向グラフ (Directed Graph)

data_array = ['文久','元治','慶応','明治','大正','昭和','平成','令和']

# 指定した閉路上の頂点と辺を追加
G.add_cycle(data_array)
#
nx.nx_agraph.view_pygraphviz(G, prog='fdp')
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------
실행 결과

사용된 NetworkX 버전
$ python
Python 3.7.3 (default, Mar 26 2019, 21:43:19) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import networkx
>>> networkx.__version__
'2.2'

좋은 웹페이지 즐겨찾기