Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions qspectrumanalyzer/plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import collections, math

from Qt import QtCore
from Qt import QtCore, QtGui
import pyqtgraph as pg

# Basic PyQtGraph settings
Expand Down Expand Up @@ -308,28 +308,39 @@ def update_plot(self, data_storage):
"""Update waterfall plot"""
self.counter += 1

# Create waterfall image on first run
if self.counter == 1:
self.waterfallImg = pg.ImageItem()
self.waterfallImg.scale((data_storage.x[-1] - data_storage.x[0]) / len(data_storage.x), 1)

x0 = data_storage.x[0]
x1 = data_storage.x[-1]
n = len(data_storage.x)
dx = (x1 - x0) / (n - 1) if n > 1 else 1.0

self._wf_rect_x0 = x0
self._wf_rect_dx = dx
self._wf_rect_w = (x1 - x0) + dx

self.plot.clear()
self.plot.addItem(self.waterfallImg)

# Roll down one and replace leading edge with new data
self.waterfallImg.setImage(data_storage.history.buffer[-self.counter:].T,
autoLevels=False, autoRange=False)

# Move waterfall image to always start at 0
self.waterfallImg.setPos(
data_storage.x[0],
-self.counter if self.counter < self.history_size else -self.history_size
self.waterfallImg.setImage(
data_storage.history.buffer[-self.counter:].T,
autoLevels=False,
autoRange=False,
)

# Link histogram widget to waterfall image on first run
# (must be done after first data is received or else levels would be wrong)
x0 = self._wf_rect_x0
dx = self._wf_rect_dx
w = self._wf_rect_w
h = float(self.history_size)

self.waterfallImg.setRect(QtCore.QRectF(x0 - dx / 2, -h, w, h))
self.waterfallImg.setPos(0.0, 0.0)

if self.counter == 1 and self.histogram_layout:
self.histogram.setImageItem(self.waterfallImg)


def clear_plot(self):
"""Clear waterfall plot"""
self.counter = 0
Expand All @@ -339,10 +350,19 @@ def recalculate_plot(self, data_storage):
if data_storage.x is None:
return

self.waterfallImg.setImage(data_storage.history.buffer[-self.counter:].T,
autoLevels=False, autoRange=False)
self.waterfallImg.setPos(
data_storage.x[0],
-self.counter if self.counter < self.history_size else -self.history_size
self.waterfallImg.setImage(
data_storage.history.buffer[-self.counter:].T,
autoLevels=False,
autoRange=False,
)
self.histogram.setImageItem(self.waterfallImg)

x0 = self._wf_rect_x0
dx = self._wf_rect_dx
w = self._wf_rect_w
h = float(self.history_size)

self.waterfallImg.setRect(QtCore.QRectF(x0 - dx / 2, -h, w, h))
self.waterfallImg.setPos(0.0, 0.0)

if self.histogram_layout:
self.histogram.setImageItem(self.waterfallImg)