forked from awendt/pyrelacs
[ui/plots] removing plotitem if the function gets called again, setting autorang
This commit is contained in:
parent
bbc8def460
commit
fe3e142452
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user