• 发表于 4年前
• 阅读 11158
• 收藏 10
• 评论 0

1. numpy https://pypi.python.org/packages/2.6/n/numpy/numpy-1.6.1.win32-py2.6.exe#md5=67e0c10cf55b713bd27cbba94dee9673

2. pyparsing http://ncu.dl.sourceforge.net/project/pyparsing/pyparsing/pyparsing-2.0.1/pyparsing-2.0.1.win32-py2.6.exe

3. datautil https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.2.tar.gz#md5=c1f654d0ff7e33999380a8ba9783fd5c

4. matplotlib http://ncu.dl.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.1/matplotlib-1.3.1.win32-py2.6.exe

5. networkx https://pypi.python.org/packages/source/n/networkx/networkx-1.8.1.zip#md5=4a90328898d9db29bbb12ef3e6223bab

6. six https://pypi.python.org/packages/source/s/six/six-1.5.2.tar.gz#md5=322b86d0c50a7d165c05600154cecc0a

``````#-*- coding:utf8-*-

import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
nx.draw(G)
plt.savefig("youxiangtu.png")
plt.show()``````

8节点完全图

``````import networkx as nx
import matplotlib.pyplot as plt
G = nx.complete_graph(8)
nx.draw(G)
plt.savefig("8nodes.png")
plt.show()``````

``````#-*- coding:utf8-*-

import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
nx.draw(G)
plt.savefig("wuxiangtu.png")
plt.show()``````

``````import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
pos = nx.spring_layout(G)

colors = [1,2,2,2,3,1]
nx.draw_networkx_nodes(G,pos,node_color=colors)
nx.draw_networkx_edges(G,pos)

plt.axis('off')
plt.savefig("color_nodes.png")
plt.show()``````

``````import networkx as nx
import matplotlib.pyplot as plt

#计算1：求无向图的任意两点间的最短路径
G = nx.Graph()
path = nx.all_pairs_shortest_path(G)
print path[1]

#计算2：求出图中在环上的点
G = nx.Graph()
path = nx.all_pairs_shortest_path(G)
print path[1]``````

{1: [1], 2: [1, 2], 3: [1, 3], 4: [1, 4], 5: [1, 5], 6: [1, 4, 6]}

{1: [1], 2: [1, 2], 3: [1, 3], 4: [1, 4], 5: [1, 5], 6: [1, 4, 6]}

×