source: orange/docs/reference/rst/code/network-constructor-nx.py @ 9823:7f9c3f3c6474

Revision 9823:7f9c3f3c6474, 720 bytes checked in by lanumek, 2 years ago (diff)

Changed names of data sets (table replaced with data or name of the data set).

Line 
1import Orange.network
2
3from matplotlib import pyplot as plt
4
5# vertices are placed randomly in Network constructor
6net = Orange.network.Graph()
7net.add_nodes_from(range(5))
8
9# set edges
10for i in range(4):
11    for j in range(i + 1, 5):
12        net.add_edge(i, j)
13
14net_layout = Orange.network.GraphLayout()
15net_layout.set_graph(net)
16
17# read all edges and plot a line
18for u, v in net.edges():
19    x1, y1 = net_layout.coors[0][u], net_layout.coors[1][u]
20    x2, y2 = net_layout.coors[0][v], net_layout.coors[1][v]
21    plt.plot([x1, x2], [y1, y2], 'b-')
22
23# read x and y coordinates to Python list
24x = net_layout.coors[0]
25y = net_layout.coors[1]
26
27# plot vertices
28plt.plot(x, y, 'ro')
29plt.savefig("network-constructor-nx.png")
Note: See TracBrowser for help on using the repository browser.