source: orange/docs/reference/rst/code/network-read-nx.py @ 9372:aef193695ea9

Revision 9372:aef193695ea9, 640 bytes checked in by mitar, 2 years ago (diff)

Moved documentation to the separate directory.

Line 
1import Orange.network
2
3from matplotlib import pyplot as plt
4
5# read network from file
6net = Orange.network.readwrite.read("K5.net")
7
8# network layout object to work with network coordinates
9net_layout = Orange.network.GraphLayout()
10net_layout.set_graph(net)
11
12# read all edges and plot a line
13for u, v in net.edges():
14    x1, y1 = net_layout.coors[0][u], net_layout.coors[1][u]
15    x2, y2 = net_layout.coors[0][v], net_layout.coors[1][v]
16    plt.plot([x1, x2], [y1, y2], 'b-')
17
18# read x and y coordinates to Python list
19x = net_layout.coors[0]
20y = net_layout.coors[1]
21
22# plot vertices
23plt.plot(x, y, 'ro')
24plt.savefig("network-read.py.png")
Note: See TracBrowser for help on using the repository browser.