source: orange/orange/doc/Orange/rst/code/network-optimization.py @ 7257:3ec7d25ecfd2

Revision 7257:3ec7d25ecfd2, 749 bytes checked in by miha <miha.stajdohar@…>, 3 years ago (diff)
Line 
1import Orange.network
2from pylab import *
3
4# create graph object of type GraphAsList
5net = Orange.network.Network(5, 0)
6
7# set edges
8for i in range(4):
9    for j in range(i + 1, 5):
10        net[i,j] = 1
11
12# vertices are placed randomly in NetworkOptimization constructor
13networkOptimization = Orange.network.NetworkOptimization(net)
14
15# optimize verices layout with one of included algorithms
16networkOptimization.fruchtermanReingold(100, 1000)
17
18# read all edges and plot a line
19for u, v in net.getEdges():
20    x1, y1 = net.coors[0][u], net.coors[1][u]
21    x2, y2 = net.coors[0][v], net.coors[1][v]
22    plot([x1, x2], [y1, y2], 'b-')
23
24# read x and y coordinates to Python list
25x = net.coors[0]
26y = net.coors[1]
27
28# plot vertices
29plot(x, y, 'ro')
30show()
Note: See TracBrowser for help on using the repository browser.