LoginSignup
1
1

More than 5 years have passed since last update.

NetworkX の使い方

Last updated at Posted at 2019-04-16

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")
# ------------------------------------------------------------------

実行結果
number01.png

ラベルを使う例

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")
# ------------------------------------------------------------------

実行結果
label01.png

使った 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'
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1