forked from M-Labs/artiq
applets: add plot_hist dataset length mismatch warning (#1718)
This commit is contained in:
parent
d327d2a505
commit
5cd721c514
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import PyQt5 # make sure pyqtgraph imports Qt5
|
import PyQt5 # make sure pyqtgraph imports Qt5
|
||||||
|
from PyQt5.QtCore import QTimer
|
||||||
import pyqtgraph
|
import pyqtgraph
|
||||||
|
|
||||||
from artiq.applets.simple import TitleApplet
|
from artiq.applets.simple import TitleApplet
|
||||||
|
@ -10,6 +11,9 @@ class HistogramPlot(pyqtgraph.PlotWidget):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
pyqtgraph.PlotWidget.__init__(self)
|
pyqtgraph.PlotWidget.__init__(self)
|
||||||
self.args = args
|
self.args = args
|
||||||
|
self.timer = QTimer()
|
||||||
|
self.timer.setSingleShot(True)
|
||||||
|
self.timer.timeout.connect(self.length_warning)
|
||||||
|
|
||||||
def data_changed(self, data, mods, title):
|
def data_changed(self, data, mods, title):
|
||||||
try:
|
try:
|
||||||
|
@ -24,10 +28,19 @@ class HistogramPlot(pyqtgraph.PlotWidget):
|
||||||
x = list(range(len(y)+1))
|
x = list(range(len(y)+1))
|
||||||
|
|
||||||
if len(y) and len(x) == len(y) + 1:
|
if len(y) and len(x) == len(y) + 1:
|
||||||
|
self.timer.stop()
|
||||||
self.clear()
|
self.clear()
|
||||||
self.plot(x, y, stepMode=True, fillLevel=0,
|
self.plot(x, y, stepMode=True, fillLevel=0,
|
||||||
brush=(0, 0, 255, 150))
|
brush=(0, 0, 255, 150))
|
||||||
self.setTitle(title)
|
self.setTitle(title)
|
||||||
|
else:
|
||||||
|
self.timer.start(1000)
|
||||||
|
|
||||||
|
def length_warning(self):
|
||||||
|
self.clear()
|
||||||
|
text = "⚠️ dataset lengths mismatch:\n"\
|
||||||
|
"There should be one more bin boundaries than there are Y values"
|
||||||
|
self.addItem(pyqtgraph.TextItem(text))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in New Issue