-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdegreePlot.py
More file actions
40 lines (32 loc) · 884 Bytes
/
degreePlot.py
File metadata and controls
40 lines (32 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from matplotlib import pyplot
import numpy
import os
import sys
def main():
if(len(sys.argv) < 2):
sys.stderr.write("Miss file to plot \n")
return 0
data_file = open(sys.argv[1],"rt")
ID = []
degree = []
with data_file as file:
for line in file:
n1, n2 = map(int, line.split())
ID.append(n1)
degree.append(n2)
setDegree = list(range(min(degree), max(degree)+1,1))
degreePOP = [0] * (max(degree) - min(degree) + 1)
for id in ID:
degreePOP[degree[id] - min(degree)] += 1
fig1, ax1 = pyplot.subplots()
ax1.bar(setDegree, degreePOP, label="Degree plot")
ax1.set_axisbelow(True)
ax1.grid(True)
ax1.set_xlabel("Degree")
ax1.set_ylabel("Number of vertices")
ax1.set_title("Degree distribution")
fig1.tight_layout()
fig1.savefig("degreePlot.png", dpi=300)
return 0
if __name__ == "__main__":
main()