plots.py added
This commit is contained in:
parent
ac8ff99e85
commit
0f836cf5fa
61
PycharmProjects/3.5.1 auto/plots.py
Normal file
61
PycharmProjects/3.5.1 auto/plots.py
Normal file
@ -0,0 +1,61 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import random
|
||||
|
||||
|
||||
def get_point(part):
|
||||
if part == 1:
|
||||
v1 = open('voltmeter1.txt')
|
||||
i1 = open('ampere-meter1.txt')
|
||||
vol[0].append(float(v1.readline()))
|
||||
cur[0].append(float(i1.readline()))
|
||||
newv1 = v1.read().replace(str(vol[0][-1]) + '\n', '')
|
||||
newi1 = i1.read().replace(str(cur[0][-1]) + '\n', '')
|
||||
v1.close()
|
||||
i1.close()
|
||||
v1 = open('voltmeter1.txt', 'w')
|
||||
v1.write(newv1)
|
||||
i1 = open('ampere-meter1.txt', 'w')
|
||||
i1.write(newi1)
|
||||
v1.close()
|
||||
i1.close()
|
||||
|
||||
elif part == 2:
|
||||
v2 = open('voltmeter2.txt')
|
||||
i2 = open('ampere-meter2.txt')
|
||||
vol[1].append(float(v2.readline()))
|
||||
cur[1].append(float(i2.readline()))
|
||||
newv2 = v2.read().replace(str(vol[1][-1]) + '\n', '')
|
||||
newi2 = i2.read().replace(str(cur[1][-1]) + '\n', '')
|
||||
v2.close()
|
||||
i2.close()
|
||||
v2 = open('voltmeter2.txt', 'w')
|
||||
v2.write(newv2)
|
||||
i2 = open('ampere-meter2.txt', 'w')
|
||||
i2.write(newi2)
|
||||
v2.close()
|
||||
i2.close()
|
||||
if part == 3:
|
||||
vol[2].append(random.random() * 100)
|
||||
cur[2].append(random.random() * 100)
|
||||
|
||||
def update_plot(part):
|
||||
for i in range(10):
|
||||
get_point(part)
|
||||
plt.figure(figsize=(8, 6))
|
||||
plt.scatter(cur[part - 1], vol[part - 1], marker='o')
|
||||
plt.grid()
|
||||
plt.savefig('tmpplot' + str(part) + '.jpg', dpi=200)
|
||||
plt.close()
|
||||
|
||||
def empty_plot(part):
|
||||
vol[part - 1] = []
|
||||
cur[part - 1] = []
|
||||
plt.figure(figsize=(8, 6))
|
||||
plt.scatter(cur[part - 1], vol[part - 1], marker='o')
|
||||
plt.grid()
|
||||
plt.savefig('tmpplot' + str(part) + '.jpg', dpi=200)
|
||||
plt.close()
|
||||
|
||||
|
||||
vol = [[], [], []]
|
||||
cur = [[], [], []]
|
Loading…
Reference in New Issue
Block a user