source: orange/orange/doc/Orange/rst/code/network-graph-analysis.py @ 7768:ec9a34c8739a

Revision 7768:ec9a34c8739a, 1.4 KB checked in by miha <miha.stajdohar@…>, 3 years ago (diff)

Changed from pylab import * to from matplotlib import pyplot as plt.
Save image to file instead of opening a pylab widget.

Line 
1import Orange.network
2
3from matplotlib import pyplot as plt
4
5# vertices are placed randomly in NetworkOptimization constructor
6network = Orange.network.NetworkOptimization()
7
8# read network from file
9net = Orange.network.Network.read("combination.net")
10
11components = net.getConnectedComponents()
12print "Connected components"
13print components
14print
15
16distribution = net.getDegreeDistribution()
17print "Degree distribution"
18print distribution
19print
20
21degrees = net.getDegrees()
22print "Degrees"
23print degrees
24print
25
26hubs = net.getHubs(3)
27print "Hubs"
28print hubs
29print
30
31path = net.getShortestPaths(0, 2)
32print "Shortest path"
33print path
34print
35
36distance = net.getDistance(0, 2)
37print "Distance"
38print distance
39print
40
41diameter = net.getDiameter()
42print "Diameter"
43print diameter
44print
45
46subnet = Orange.network.Network(net.getSubGraph([0, 1, 2, 3]))
47subNetOptimization = Orange.network.NetworkOptimization(subnet)
48subNetOptimization.fruchtermanReingold(100, 1000)
49
50# read all edges in subnetwork and plot a line
51for u, v in subnet.getEdges():
52    x1, y1 = subnet.coors[0][u], subnet.coors[1][u]
53    x2, y2 = subnet.coors[0][v], subnet.coors[1][v]
54    plt.plot([x1, x2], [y1, y2], 'b-')       
55       
56# read x and y coordinates to Python list
57x = [coordinate for coordinate in subnet.coors[0]]
58y = [coordinate for coordinate in subnet.coors[1]]
59
60# plot vertices of subnetwork
61plt.plot(x, y, 'ro')
62plt.savefig("network-graph-analysis.py.png")
Note: See TracBrowser for help on using the repository browser.