-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisible function.py
More file actions
58 lines (44 loc) · 1.03 KB
/
visible function.py
File metadata and controls
58 lines (44 loc) · 1.03 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
55
56
57
58
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 14 18:37:40 2021
@author: Hens
"""
import numpy as np
import matplotlib.pyplot as plt
f1 = open("function1.txt", 'r')
f2 = open("function2.txt", 'r')
x = np.arange(-1, 1, 0.001)
orgFun = []
predictFun1 = []
predictFun2 = []
x = []
y = []
for cnt in x:
s = f1.readline()
orgFun.append(float(s.strip())) #real
s = f1.readline()
predictFun1.append(float(s.strip())) #predict
orgFun = []
for cnt in x:
s = f2.readline()
orgFun.append(float(s.strip())) #real
s = f2.readline()
predictFun2.append(float(s.strip())) #predict
orgFun = np.array(orgFun)
predictFun1 = np.array(predictFun1)
predictFun2 = np.array(predictFun2)
plt.figure()
plt.xlabel("x")
plt.ylabel("y")
plt.plot(x, orgFun, 'r')
plt.plot(x, predictFun1, 'g')
plt.plot(x, predictFun2, 'b')
dotf = open("xy.txt", 'r')
n = int(dotf.readline().strip())
for i in range(n):
s = dotf.readline()
x.append(float(s.strip()))
s = dotf.readline()
y.append(float(s.strip()))
plt.scatter(x, y)
plt.show()