-
Notifications
You must be signed in to change notification settings - Fork 0
/
LivePlot.py
142 lines (121 loc) · 5.22 KB
/
LivePlot.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
class FrequencyPlot(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
# Create a Figure and Canvas
plt.ion()
self.fig, self.ax = plt.subplots()
super().__init__(self.fig)
self.setParent(parent)
# Data to plot
self.x_data = []
self.y_data = []
self.line, = self.ax.plot(self.x_data, self.y_data, '-g')
self.ax.set_xlabel('Time (s)')
self.ax.set_ylabel('Frequency (MHz)')
self.ax.set_title('Frequency Sweep')
def init_plot(self, x_min: float = 0.0, x_max: float = 100.0, y_min: float = 0.0, y_max: float = 500.0):
print("Initializing plot: x_min = {}, x_max = {}, y_min = {}, y_max = {}".format(x_min, x_max, y_min, y_max))
self.ax.set_xlim(x_min, x_max)
self.ax.set_ylim(y_min, y_max)
self.line.set_data(self.x_data, self.y_data)
self.ax.relim()
self.ax.autoscale_view()
self.draw_idle()
return self.line,
def update_plot(self, time: float, freq: float):
#print("Updating plot: x = {}, y = {}".format(x, y))
self.x_data.append(time)
self.y_data.append(freq)
if (time > self.ax.get_xlim()[1]):
self.ax.set_xlim(self.x_data[0], self.x_data[-1] + 0.1)
self.line.set_data(self.x_data, self.y_data)
self.ax.relim()
self.ax.autoscale_view()
self.draw_idle()
return self.line,
def clear_plot(self):
print("Clearing plot")
self.x_data.clear()
self.y_data.clear()
self.line.set_data(self.x_data, self.y_data)
self.ax.relim()
self.ax.autoscale_view()
self.draw_idle()
return self.line,
class PowerPlot(FigureCanvas):
def __init__(self, parent=None, width=5, height=4, dpi=100):
# Create a Figure and Canvas
plt.ion()
self.fig, self.ax = plt.subplots()
super().__init__(self.fig)
self.setParent(parent)
# Data to plot
self.freq_data = []
self.setpoint_data = []
self.composite_data = []
self.x_data = []
self.y_data = []
self.z_data = []
self.line1, = self.ax.plot(self.freq_data, self.setpoint_data, '-b', label='Setpoint')
self.line2, = self.ax.plot(self.freq_data, self.composite_data, '-r', label='Composite')
self.line3, = self.ax.plot(self.freq_data, self.x_data, '-g', label='X')
self.line4, = self.ax.plot(self.freq_data, self.y_data, '-c', label='Y')
self.line5, = self.ax.plot(self.freq_data, self.z_data, '-y', label='Z')
self.ax.set_xlim(0, 10)
self.ax.set_ylim(0, 10)
self.ax.relim()
self.ax.autoscale_view()
self.ax.set_xlabel('Frequency (MHz)')
self.ax.set_ylabel('E-Field (V/m)')
self.ax.set_title('Field Strength')
self.ax.legend()
self.draw_idle()
def rescale_plot(self, x_min: float = 0.0, x_max: float = 10.0, y_min: float = 0.0, y_max: float = 10.0):
print("Rescaling plot: x_min = {}, x_max = {}, y_min = {}, y_max = {}".format(x_min, x_max, y_min, y_max))
self.ax.set_xlim(x_min, x_max)
self.ax.set_ylim(y_min, y_max)
self.ax.relim()
self.ax.autoscale_view()
self.draw_idle()
return self.line1, self.line2, self.line3, self.line4, self.line5
def clear_plot(self):
print("Clearing plot")
self.freq_data.clear()
self.setpoint_data.clear()
self.composite_data.clear()
self.x_data.clear()
self.y_data.clear()
self.z_data.clear()
#self.ax.set_xlim(0, self.ax.get_xlim()[1] - self.ax.get_xlim()[0])
self.ax.relim()
self.ax.autoscale_view()
self.draw_idle()
return self.line1, self.line2, self.line3, self.line4, self.line5
def update_plot(self, freq: float, setpoint: float, composite: float, x: float, y: float, z: float):
print("Updating plot: freq = {}, setpoint = {}, composite = {}, x = {}, y = {}, z = {}".format(freq, setpoint, composite, x, y, z))
self.freq_data.append(freq)
self.setpoint_data.append(setpoint)
self.composite_data.append(composite)
self.x_data.append(x)
self.y_data.append(y)
self.z_data.append(z)
'''
if (freq > self.ax.get_xlim()[1]):
self.freq_data.pop(0)
self.setpoint_data.pop(0)
self.composite_data.pop(0)
self.x_data.pop(0)
self.y_data.pop(0)
self.z_data.pop(0)
self.ax.set_xlim(self.freq_data[0], self.freq_data[-1] + 0.1)
'''
self.line1.set_data(self.freq_data, self.setpoint_data)
self.line2.set_data(self.freq_data, self.composite_data)
self.line3.set_data(self.freq_data, self.x_data)
self.line4.set_data(self.freq_data, self.y_data)
self.line5.set_data(self.freq_data, self.z_data)
self.ax.relim()
self.ax.autoscale_view()
self.draw_idle()
return self.line1, self.line2, self.line3, self.line4, self.line5