source: orange/orange/doc/Orange/rst/code/network-optimization.py @ 7771:ec73cd1b51a4

Revision 7771:ec73cd1b51a4, 820 bytes checked in by miha <miha.stajdohar@…>, 3 years ago (diff)

Call new underscore case functions.

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# optimize verices layout with one of included algorithms
17networkOptimization.radial_fruchterman_reingold(100, 1000)
18
19# read all edges and plot a line
20for u, v in net.get_edges():
21    x1, y1 = net.coors[0][u], net.coors[1][u]
22    x2, y2 = net.coors[0][v], net.coors[1][v]
23    plt.plot([x1, x2], [y1, y2], 'b-')
24
25# read x and y coordinates to Python list
26x = net.coors[0]
27y = net.coors[1]
28
29# plot vertices
30plt.plot(x, y, 'ro')
31plt.savefig("network-optimization.py.png")
Note: See TracBrowser for help on using the repository browser.