From fe3e142452f7ee1787e4a8f2619f798acc61f5ab Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Thu, 10 Oct 2024 14:22:03 +0200 Subject: [PATCH] [ui/plots] removing plotitem if the function gets called again, setting autorang --- pyrelacs/ui/plots/continously.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pyrelacs/ui/plots/continously.py b/pyrelacs/ui/plots/continously.py index f851e21..8e48173 100644 --- a/pyrelacs/ui/plots/continously.py +++ b/pyrelacs/ui/plots/continously.py @@ -1,9 +1,8 @@ -import time import pyqtgraph as pg from IPython import embed import numpy as np +from pyqtgraph.Qt.QtCore import QTimer -from PyQt6.QtCore import QTimer from pyrelacs.dataio.circbuffer import CircBuffer from pyrelacs.util.logging import config_logging @@ -17,11 +16,16 @@ class Continously: def plot_daq(self, *args, **kwargs): self.figure.setBackground("w") - self.daq_plot = self.figure.addPlot(row=0, col=0) + + prev_plot = self.figure.getItem(row=0, col=0) + if prev_plot: + self.figure.removeItem(prev_plot) + self.continous_plot = self.figure.addPlot(row=0, col=0) + pen = pg.mkPen("red") self.time = np.zeros(self.buffer.size) self.data = np.zeros(self.buffer.size) - self.line = self.daq_plot.plot( + self.line = self.continous_plot.plot( self.time, self.data, pen=pen, @@ -29,8 +33,8 @@ class Continously: ) # self.plot_index = 0 - self.CHUNK_PLOT = 1_000 self.timer = QTimer() + self.CHUNK_PLOT = 10_000 self.timer.setInterval(200) self.timer.timeout.connect(self.update_plot) self.timer.start() @@ -41,7 +45,8 @@ class Continously: log.debug(self.buffer.totalcount()) try: times, items = self.buffer.read( - self.buffer.write_index() - self.CHUNK_PLOT, extend=self.CHUNK_PLOT + self.buffer.write_index() - self.CHUNK_PLOT - 1_000, + extend=self.CHUNK_PLOT, ) except IndexError as e: items = np.zeros(self.CHUNK_PLOT) @@ -65,3 +70,6 @@ class Continously: def stop_plotting(self): self.timer.stop() + + def refresh(self): + self.continous_plot.enableAutoRange()