-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphclass.py
71 lines (55 loc) · 2.16 KB
/
graphclass.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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
"""graphclass.py
Created by Amit Sandhel with contributions by Fredrick Leber.
This script is designed to display the graph in real time.
Note: this script requires:
1) Python 2.7
2) Matplotlib
"""
# Does matplotlib exist on library
try:
import matplotlib.pyplot as plt
except:
print('Error: Please install matplotlib.')
class GraphClass():
"""Takes the data and displays it in real time."""
def __init__(self):
# setting up figure variables
# self.fig = plt.figure(1) # this line is not necessary
self.ax1 = plt.subplot(2, 1, 1)
self.ax2 = plt.subplot(2, 1, 2)
# lists to access data
self.time_list = []
self.bias_list = []
self.current_list = []
def analysis(self, timeData, BIASData, TPData):
"""appends the data obtained from beastie into individual lists and
then graphs the elements of each list. (Used to be last 5 elements)
"""
self.time_list.append(timeData)
self.bias_list.append(BIASData)
self.current_list.append(TPData)
# call graph function and graphs last 5 elements of each list
self.graph()
def graph(self):
"""Graph function, uses self variables for graphing."""
# clear the axis each iteration
self.ax1.cla()
self.ax2.cla()
# labeling the time axis and the voltage bias axis
self.ax1.set_ylabel('Voltage Bias (mV)')
self.ax2.set_xlabel('Time (seconds)')
# autoscale the graph
plt.autoscale(enable=True, axis='both', tight=False)
# plotting the graph with color
self.ax1.plot(self.time_list, self.bias_list, "-m")
# autoscale the axis
plt.autoscale(enable=True, axis='both', tight=False)
# plotting the graph with color
self.ax2.plot(self.time_list, self.current_list, "-r")
# Allows graphing in "real time". Every iteration new plot is displayed
plt.show(block=False)
plt.draw()
###############################################################################
if __name__ == '__main__':
print('Welcome to my Graphclass Graphing Environment!\n')
GraphClass()