diff --git a/pyrelacs/ui/plots/continously.py b/pyrelacs/ui/plots/continously.py index 297591d..ece2ca2 100644 --- a/pyrelacs/ui/plots/continously.py +++ b/pyrelacs/ui/plots/continously.py @@ -16,6 +16,7 @@ class Continously: self.figure = figure self.buffer = buffer self.last_plotted_index = 0 + self.timer = QTimer() def plot(self, *args, **kwargs): self.figure.setBackground("w") @@ -36,7 +37,6 @@ class Continously: ) # self.plot_index = 0 - self.timer = QTimer() self.CHUNK_PLOT = int(self.buffer.samplerate / 6) self.PLOT_HISTORY = 500_000 # The amount of data you want to keep on screen self.timer.setInterval(150) @@ -70,18 +70,19 @@ class Continously: def stop_plotting(self): self.timer.stop() - total_count = self.buffer.totalcount() - times, items = self.buffer.read( - self.last_plotted_index, - extend=total_count - self.last_plotted_index, - ) - self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :] - self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :] - self.line.setData( - self.time, - self.data, - ) - self.last_plotted_index += total_count - self.last_plotted_index + if self.last_plotted_index > 0: + total_count = self.buffer.totalcount() + times, items = self.buffer.read( + self.last_plotted_index, + extend=total_count - self.last_plotted_index, + ) + self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :] + self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :] + self.line.setData( + self.time, + self.data, + ) + self.last_plotted_index += total_count - self.last_plotted_index def refresh(self): self.continous_ax.enableAutoRange()