-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
54 lines (46 loc) · 1.18 KB
/
script.py
File metadata and controls
54 lines (46 loc) · 1.18 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import matplotlib.pyplot as plt
import math
import sys
input = "Graph1.txt"
output = "Graph1.png"
title = "Error analysis with Mat_N = 10 (log_2 Scale)"
""" Examples.
Default: Graph 1.
$ python3 script.py 1
Optional: Graph2.
$ python3 script.py 2
"""
if len(sys.argv) == 2:
if sys.argv[1] == "2":
input = "Graph2.txt"
output = "Graph2.png"
title = "Error analysis with Mat_N = 300 (log_2 Scale)"
print("User's choice: Graph 2.")
else:
print("User's choice: Graph 1.")
else:
print("User's choice: Graph 1.")
print()
print("Reading from:", input);
with open(input, "r") as f:
X = []
Y = []
for line in f:
x, y = map(float, line.split())
# We can choose between log_2 and natural log.
# x = math.log(x)
# y = math.log(y)
x = math.log(x, 2)
y = math.log(y, 2)
X.append(x)
Y.append(y)
# print("X = ", X)
# print("Y = ", Y)
plt.plot(X, Y, label="log(r) -> log_2 || B-Br ||")
plt.title(title)
plt.xlabel("log(r)")
plt.ylabel("log_2 || B-Br ||")
plt.legend()
plt.savefig(output)
plt.clf()
print("Graph plotted at:", output)