-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
31 lines (24 loc) · 860 Bytes
/
graph.py
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
import numpy as np
from values import Values
from syssolver import Solver
import matplotlib.pyplot as plt
def Graph(filename, n, xlabel = '', ylabel = ''):
t = np.arange(Values(filename)[0][0], Values(filename)[0][-1], 0.2)
p = 0
i = 0
while i <= n: p = p + Solver(filename, n)[i]*(t**i); i = i + 1
plt.plot(Values(filename)[0], Values(filename)[1], 'bo', label="Data")
if n == 1:
plt.plot(t, p, 'k', label="First degree polynomial")
elif n == 2:
plt.plot(t, p, 'k', label="Second degree polynomial")
elif n == 3:
plt.plot(t, p, 'k', label="Third degree polynomial")
else:
plt.plot(t, p, 'k', label="{}th degree polynomial".format(n))
plt.xlabel(xlabel)
plt.ylabel(ylabel)
#plt.legend()
plt.ylim([0, 0.015])
plt.show()
#plt.savefig('{}th degree'.format(n))