1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NetworkXのグラフに矢印を付ける

矢印が付いていないグラフを無向グラフ、矢印が付いているグラフを有向グラフと言う。
グラフ理論とかネットワーク理論とかは難しすぎてわからないので、お詳しい方に教えていただきたいのだけれど、この無向・有向の定義は間違っていないはず。

NetworkXでの実装は、とても簡単。

import networkx as nx
import matplotlib.pyplot as plt

G = nx.DiGraph()
G.add_node(1)
G.add_edge(1, 2)

nx.draw_networkx(G, node_color='lightblue', edge_color='dimgray')
plt.savefig('file03.png')

4行目でこれまではG = nx.Graph() だったところを、G = nx.DiGraph() にするだけだ。
これで有向グラフになる。ちなみに、DiGraphはDirected Graphのこと。

file03.png

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?