74 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import matplotlib.pyplot as plt
 | |
| import random
 | |
| 
 | |
| 
 | |
| def get_point(part, num):
 | |
|     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()
 | |
|     elif part == 3:
 | |
|         vol[2][num].append(random.random() * 100)
 | |
|         cur[2][num].append(random.random() * 100)
 | |
|     elif part == 4:
 | |
|         vol[3][num].append(random.random() * 100)
 | |
|         cur[3][num].append(random.random() * 100)
 | |
| 
 | |
| def update_plot(part, num):
 | |
|     for i in range(10):
 | |
|         get_point(part, num)
 | |
| 
 | |
| def saveplot(part):
 | |
|     plt.figure(figsize=(8, 6))
 | |
|     for i in range(len(vol[part - 1])):
 | |
|         plt.scatter(cur[part - 1][i], vol[part - 1][i], marker='o')
 | |
|     plt.grid()
 | |
|     plt.savefig('tmpplots/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('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
 | |
|     plt.close()
 | |
| 
 | |
| def plus_plot(part):
 | |
|     vol[part - 1].append([])
 | |
|     cur[part - 1].append([])
 | |
| 
 | |
| def minus_plot(part):
 | |
|     vol[part - 1].pop()
 | |
|     cur[part - 1].pop()
 | |
| 
 | |
| vol = [[], [], [[]], [[]]]
 | |
| cur = [[], [], [[]], [[]]] |