[ui/plots] updating plot
This commit is contained in:
parent
5d62cb0384
commit
85b5a71ccb
@ -1,3 +1,5 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -24,7 +26,7 @@ class Continously:
|
|||||||
|
|
||||||
pen = pg.mkPen("red")
|
pen = pg.mkPen("red")
|
||||||
self.time = np.zeros(self.buffer.size)
|
self.time = np.zeros(self.buffer.size)
|
||||||
self.data = np.zeros(self.buffer.size)
|
self.data = np.empty(self.buffer.size)
|
||||||
self.line = self.continous_ax.plot(
|
self.line = self.continous_ax.plot(
|
||||||
self.time,
|
self.time,
|
||||||
self.data,
|
self.data,
|
||||||
@ -34,37 +36,32 @@ class Continously:
|
|||||||
|
|
||||||
# self.plot_index = 0
|
# self.plot_index = 0
|
||||||
self.timer = QTimer()
|
self.timer = QTimer()
|
||||||
self.CHUNK_PLOT = 10_000
|
self.CHUNK_PLOT = 500
|
||||||
self.timer.setInterval(200)
|
self.PLOT_HISTORY = 500_000 # The amount of data you want to keep on screen
|
||||||
|
self.last_plotted_index = 0
|
||||||
|
self.timer.setInterval(150)
|
||||||
self.timer.timeout.connect(self.update_plot)
|
self.timer.timeout.connect(self.update_plot)
|
||||||
self.timer.start()
|
self.timer.start()
|
||||||
|
|
||||||
def update_plot(self):
|
def update_plot(self):
|
||||||
# log.debug(self.buffer.totalcount())
|
current_index = self.buffer.write_index()
|
||||||
if self.buffer.totalcount() > self.CHUNK_PLOT:
|
total_count = self.buffer.totalcount()
|
||||||
log.debug(self.buffer.totalcount())
|
|
||||||
try:
|
start_time = time.time()
|
||||||
|
if total_count - self.last_plotted_index >= self.CHUNK_PLOT:
|
||||||
times, items = self.buffer.read(
|
times, items = self.buffer.read(
|
||||||
self.buffer.write_index() - self.CHUNK_PLOT - 1_000,
|
self.last_plotted_index,
|
||||||
extend=self.CHUNK_PLOT,
|
extend=self.CHUNK_PLOT,
|
||||||
)
|
)
|
||||||
except IndexError as e:
|
self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :]
|
||||||
items = np.zeros(self.CHUNK_PLOT)
|
self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :]
|
||||||
times = np.zeros(self.CHUNK_PLOT)
|
|
||||||
log.debug("No Data Available")
|
|
||||||
log.debug(f"Index Error {e}")
|
|
||||||
|
|
||||||
# self.time = np.roll(self.time, -len(items))
|
|
||||||
# self.data = np.roll(self.data, -len(items))
|
|
||||||
#
|
|
||||||
# self.time[-len(times) :] = times
|
|
||||||
# self.data[-len(items) :] = items
|
|
||||||
|
|
||||||
self.line.setData(
|
self.line.setData(
|
||||||
times,
|
self.time,
|
||||||
items,
|
self.data,
|
||||||
)
|
)
|
||||||
# self.plot_index += len(items)
|
self.last_plotted_index += self.CHUNK_PLOT
|
||||||
|
end_time = time.time()
|
||||||
|
log.debug(f"total time for plotting {end_time - start_time}")
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user