source: orange/docs/reference/rst/code/network-optimization.py @ 9839:63184e6301ce

Revision 9839:63184e6301ce, 701 bytes checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Resolved.

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