class_real_time_plot.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 """
5 
6  Real Time Plot Class
7 
8 """
9 
10 from PyQt5 import QtCore, QtWidgets
11 import numpy as np
12 import matplotlib
13 matplotlib.use("Qt5Agg")
14 from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
15 from matplotlib.figure import Figure
16 
17 
18 class MainPlot(FigureCanvas):
19  """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
20  def __init__(self, parent=None, width=5, height=4, dpi=100):
21  fig = Figure(figsize=(width, height), dpi=dpi)
22  self.axes = fig.add_subplot(111)
23 
24  # We want the axes cleared every time plot() is called
25  self.axes.hold(True)
26 
28 
29  FigureCanvas.__init__(self, fig)
30  self.setParent(parent)
31 
32  FigureCanvas.setSizePolicy(self,
33  QtWidgets.QSizePolicy.Expanding,
34  QtWidgets.QSizePolicy.Expanding)
35  FigureCanvas.updateGeometry(self)
36 
38  """
39  Compute Initial Figure Function
40  """
41 
42 
43 class StaticPlot(MainPlot):
44  """
45  Create Static Plot
46  """
47 
48  def __init__(self, x_list, y_list, *args, **kwargs):
49  MainPlot.__init__(self, *args, **kwargs)
50 
51  self.x_list = x_list
52  self.y_list = y_list
53  self.create_plot()
54 
55 
57  pass
58 
59 
60  def create_plot(self):
61  """
62  Create Plot
63  """
64  self.axes.set_ylim(0, 1)
65  self.axes.set_xlim(0, len(self.x_list)-1)
66  self.axes.plot(self.x_list, self.y_list, '-r')
67 
68 
70  """
71  Create POTC Plot
72  """
73 
74  def __init__(self, ui_class, potc_main_dict, *args, **kwargs):
75  MainPlot.__init__(self, *args, **kwargs)
76  self.ui_class = ui_class
77  self.potc_main_dict = potc_main_dict
78 
79  timer = QtCore.QTimer(self)
80  timer.timeout.connect(self.update_figure)
81  timer.start(1000)
82 
84  pass
85 
86 
87  def update_figure(self):
88  """
89  Update Figure
90  """
91  self.axes.clear()
92 
93  predict_list = list(eval("self.ui_class." + self.potc_main_dict + "['Predict']['Nominal']['POTC']"))
94  predict_time_line = list(eval("self.ui_class." + self.potc_main_dict + "['Predict']['Nominal']['Time']"))
95 
96  actual_list = list(eval("self.ui_class." + self.potc_main_dict + "['Actual']['Nominal']['POTC']"))
97  actual_time_line = list(eval("self.ui_class." + self.potc_main_dict + "['Actual']['Nominal']['Time']"))
98 
99  predict_sb_list = list(eval("self.ui_class." + self.potc_main_dict + "['Predict']['Sensor Based']['POTC']"))
100  predict_sb_time_line = list(eval("self.ui_class." + self.potc_main_dict + "['Predict']['Sensor Based']['Time']"))
101 
102  actual_sb_list = list(eval("self.ui_class." + self.potc_main_dict + "['Actual']['Sensor Based']['POTC']"))
103  actual_sb_time_line = list(eval("self.ui_class." + self.potc_main_dict + "['Actual']['Sensor Based']['Time']"))
104 
105  self.axes.set_ylim(0, 1)
106 
107  if len(predict_time_line) >= len(actual_time_line):
108  self.axes.set_xlim(0, len(predict_time_line)-1)
109 
110  else:
111  self.axes.set_xlim(0, len(actual_time_line)-1)
112 
113  self.axes.plot(predict_time_line, predict_list, '-or', label="Predict")
114  self.axes.plot(actual_time_line, actual_list, '-ob', label="Actual")
115 
116  self.axes.plot(predict_sb_time_line, predict_sb_list, '-oy', label="Predict SB")
117  self.axes.plot(actual_sb_time_line, actual_sb_list, '-og', label="Actual SB")
118 
119  self.axes.legend(loc='lower left', fontsize='small')
120  self.draw()
121 
122 
124  """
125  Create Simulation POTC Plot
126  """
127 
128  def __init__(self, ui_class, x_list, y_list, *args, **kwargs):
129  MainPlot.__init__(self, *args, **kwargs)
130  self.ui_class = ui_class
131  self.x_list_name = x_list
132  self.y_list_name = y_list
133  self.x_list = list()
134  self.y_list = list()
135 
136  timer = QtCore.QTimer(self)
137  timer.timeout.connect(self.update_figure)
138  timer.start(500)
139 
140 
142  pass
143 
144 
145  def create_plot(self):
146  """
147  Create Static Plot
148  """
149  self.axes.clear()
150  self.x_list = list(eval("self.ui_class." + self.x_list_name))
151  self.y_list = list(eval("self.ui_class." + self.y_list_name))
152 
153  self.axes.set_ylim(0, 1)
154  self.axes.set_xlim(0, len(self.x_list)-1)
155 
156  self.axes.plot(self.x_list, self.y_list, '-r')
157  self.draw()
158 
159 
160  def update_figure(self):
161  """
162  Update Figure
163  """
164  self.axes.clear()
165  self.x_list = list(eval("self.ui_class." + self.x_list_name))
166  self.y_list = list(eval("self.ui_class." + self.y_list_name))
167 
168  self.axes.set_ylim(0, 1)
169  self.axes.set_xlim(0, len(self.x_list)-1)
170 
171 
172  self.axes.plot(self.x_list, self.y_list, '-r')
173  self.draw()
174 
175 
177  """
178  Create Dynamic Plot
179  """
180 
181  def __init__(self, ui_class, ui_parameter, ui_time_parameter, *args, **kwargs):
182  MainPlot.__init__(self, *args, **kwargs)
183  self.ui_class = ui_class
184  self.ui_parameter = ui_parameter
185  self.ui_time_parameter = ui_time_parameter
186  self.amount = 30
187  timer = QtCore.QTimer(self)
188  timer.timeout.connect(self.update_figure)
189  timer.start(500)
190 
192  self.x_list = [0, 0, 0]
193  self.y_list = [0, 0, 0]
194 
195  self.axes.plot(self.x_list, self.y_list, 'r')
196 
197  @classmethod
198  def num_zeros(cls, decimal_number):
199  """
200  Find count of 0
201  """
202  return np.floor(np.abs(np.log10(decimal_number)))
203 
204 
205  def update_figure(self):
206  """
207  Update Figure
208  """
209  try:
210  plot_time = float(eval("self.ui_class." + self.ui_time_parameter))
211 
212  self.x_list.append(plot_time)
213  self.y_list.append(float(eval("self.ui_class." + self.ui_parameter + ".text()")))
214 
215  read_value = str(eval("self.ui_class." + self.ui_parameter + ".text()"))
216 
217  if read_value not in ("", "0.0"):
218  self.axes.clear()
219 
220  if read_value.find('e') != -1:
221  temp_limit_1 = read_value.split('e-')
222  value_min = int(temp_limit_1[1]) - 1
223  value_max = value_min + 2
224 
225  else:
226  zero_count = self.num_zeros(float(read_value))
227  value_min = int(zero_count)
228  value_max = value_min + 1
229 
230  self.axes.set_ylim((1.0 * pow(10, (-1 * value_max))), (1.0 * pow(10, (-1 * value_min))))
231 
232  right = self.x_list[-1]
233 
234  if len(self.x_list) > self.amount:
235  left = self.x_list[-self.amount]
236 
237  else:
238  left = self.x_list[0]
239 
240  self.axes.set_xlim(left, right)
241  self.axes.plot(self.x_list[-self.amount:], self.y_list[-self.amount:], 'r')
242  self.draw()
243 
244  except Exception as err:
245  print("\nError: DynamicPlot\n")
246  print(err)
247 
248 
250  """
251  Create Reliability Plot
252  """
253 
254  def __init__(self, ui_class, ui_parameter, ui_time_parameter, scale_list, *args, **kwargs):
255  MainPlot.__init__(self, *args, **kwargs)
256  self.ui_class = ui_class
257  self.ui_parameter = ui_parameter
258  self.ui_time_parameter = ui_time_parameter
259  self.amount = 30
260  self.scale_list = scale_list
261  timer = QtCore.QTimer(self)
262  timer.timeout.connect(self.update_figure)
263  timer.start(500)
264 
266  self.x_list = [0, 0, 0]
267  self.y_list = [0, 0, 0]
268 
269  self.axes.plot(self.x_list, self.y_list, 'r')
270 
271  def update_figure(self):
272  """
273  Update Figure
274  """
275  plot_time = float(eval("self.ui_class." + self.ui_time_parameter))
276 
277  self.x_list.append(plot_time)
278  self.y_list.append(float(eval("self.ui_class." + self.ui_parameter + ".text()")))
279 
280  self.axes.clear()
281 
282  if self.scale_list:
283  self.axes.set_ylim(0, 1)
284 
285  else:
286  self.axes.set_ylim(self.scale_list[0], self.scale_list[1])
287 
288  right = self.x_list[-1]
289 
290  if len(self.x_list) > self.amount:
291  left = self.x_list[-self.amount]
292 
293  else:
294  left = self.x_list[0]
295 
296  self.axes.set_xlim(left, right)
297  self.axes.plot(self.x_list[-self.amount:], self.y_list[-self.amount:], 'r')
298  self.draw()
def __init__(self, x_list, y_list, args, kwargs)
def __init__(self, ui_class, potc_main_dict, args, kwargs)
def __init__(self, ui_class, x_list, y_list, args, kwargs)
def __init__(self, parent=None, width=5, height=4, dpi=100)
def __init__(self, ui_class, ui_parameter, ui_time_parameter, args, kwargs)
def __init__(self, ui_class, ui_parameter, ui_time_parameter, scale_list, args, kwargs)


phm_start
Author(s):
autogenerated on Thu Aug 13 2020 16:41:50