From 0cff7d6ccaaec67abdcf69fe6237c2975aef6bf7 Mon Sep 17 00:00:00 2001 From: JayPiKay Date: Wed, 22 Jan 2020 14:36:47 +0100 Subject: [PATCH] Timer Plot Demo --- .python-version | 2 +- src/um24clab.py | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.python-version b/.python-version index bebc4ba..de84bc6 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -py3um24c +py3 diff --git a/src/um24clab.py b/src/um24clab.py index a54f5ef..9b17e6d 100644 --- a/src/um24clab.py +++ b/src/um24clab.py @@ -30,54 +30,65 @@ class UM24Lab(QMainWindow): # --- Voltage --- self.voltage = self.ui.plotVoltage - self.voltage_series = QtCharts.QLineSeries() + self.voltage_series = QtCharts.QLineSeries(self) self.voltage_series.setName('Voltage over time') + self.voltage_series.setUseOpenGL(True) self.voltage.addSeries(self.voltage_series) axis_x = QtCharts.QValueAxis() - axis_x.setTickCount(60) + axis_x.setRange(0, 0) + # axis_x.setTickCount(1) + axis_x.setTickInterval(0.001) axis_x.setTitleText('Seconds') self.voltage.addAxis(axis_x, Qt.AlignBottom) self.voltage_series.attachAxis(axis_x) axis_y = QtCharts.QValueAxis() - axis_y.setTickCount(10) + # axis_y.setTickCount(1) + axis_y.setRange(0, 10) axis_y.setTitleText('Voltage (V)') self.voltage.addAxis(axis_y, Qt.AlignLeft) self.voltage_series.attachAxis(axis_y) # --- Current --- self.current = self.ui.plotCurrent - self.current_series = QtCharts.QLineSeries() + self.current_series = QtCharts.QLineSeries(self) self.current_series.setName('Current over time') + self.current_series.setUseOpenGL(True) self.current.addSeries(self.current_series) axis_x = QtCharts.QValueAxis() - axis_x.setTickCount(60) + axis_x.setRange(0, 60000) + # axis_x.setTickCount(1) + # axis_x.setTickInterval(1) axis_x.setTitleText('Seconds') self.current.addAxis(axis_x, Qt.AlignBottom) self.current_series.attachAxis(axis_x) axis_y = QtCharts.QValueAxis() - axis_y.setTickCount(10) + # axis_y.setTickCount(1) + axis_y.setRange(0, 10) axis_y.setTitleText('Current (A)') self.current.addAxis(axis_y, Qt.AlignLeft) self.current_series.attachAxis(axis_y) self.timer_step = 0 - self.voltage_series.append(self.timer_step, 0) - self.current_series.append(self.timer_step, 0) - timer = QTimer() + timer = QTimer(self) timer.timeout.connect(self.update_graphs) - timer.start(0) + timer.start(10) def update_graphs(self): self.voltage_series.append(self.timer_step, random.randint(0, 10)) self.current_series.append(self.timer_step, random.randint(0, 10)) - self.ui.progressTempC.setValue(random.randint(0, 100)) self.timer_step += 1 - self.update() + for axis in self.voltage_series.attachedAxes(): + if axis.orientation() == Qt.Orientation.Horizontal: + axis.setRange(0, self.timer_step) + for axis in self.current_series.attachedAxes(): + if axis.orientation() == Qt.Orientation.Horizontal: + # axis.setRange(0, self.timer_step) + pass if __name__ == '__main__': @@ -86,13 +97,12 @@ if __name__ == '__main__': labview = UM24Lab() labview.show() - def idle_processor(): - labview.update_graphs() - app.processEvents() - # print(labview.timer_step) + # def idle_processor(): + # labview.update_graphs() + # app.processEvents() # mainTimer = QTimer() # mainTimer.timeout.connect(idle_processor) - # mainTimer.start(50) + # mainTimer.start(0) sys.exit(app.exec_())