Introduction
I write about basis of Gragh theory.
Please look at this page.
This post is not written Graph theory, but I want to share module in Python for Graph theory.
Networkx
Python3 have Networkx module.If you have python2, you should install by pip
pip install networkx
Make Graph by Networkx
first, import networkx module and make instance.import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
next, add node and edgeG.add_node(1)
# add Multiple nodes
G.add_nodes_from([2,3,4])
G.add_edge(1,2)
# add Multiple edges
G.add_edges_from([(3,4),(1,2),(4,6)])
next, plot Gnx.draw(G)
plt.show()
networkx have many function.
I will write new learning about networkx in this post.
Reference
https://qiita.com/kzm4269/items/081ff2fdb8a6b0a6112f
http://akiniwa.hatenablog.jp/entry/2013/05/12/012459
コメント
コメントを投稿