コード例 #1
0
class PlotSignalWindow():
    def __init__(self, width=1000, height=600):
        # signal
        self.signal = dict()
        # setup window
        self.app = QtGui.QApplication([])
        self.win = GraphicsWindow(title="Plot Signal")
        self.win.resize(width, height)
        self.win.setWindowTitle('Plot Signal')
        # enable anti-aliasing
        setConfigOptions(antialias=True)
        self.canvas = self.win.addPlot(title="Fast Fourier Transform")
        # limit plot to 20Hz to 20kHz and clamp magnitude
        # self.canvas.setXRange(0, 20000)
        self.canvas.setYRange(0, 100000)

    def start(self):
        if (flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
            QtGui.QApplication.instance().exec_()

    def draw(self, name: str, _x, _y, pen='y'):
        if name in self.signal:
            self.signal[name].setData(_x, _y)
        else:
            self.signal[name] = self.canvas.plot(pen=pen)
コード例 #2
0
class MyWaveformViewer(object):
    def __init__(self):
        super(MyWaveformViewer, self).__init__()
        self.win = GraphicsWindow()
        self.p1 = self.win.addPlot()
        self.ptr = 0
        self.init_ui()
        self.init_timer()

    def init_ui(self):
        self.win.setWindowTitle('Plot Demo')
        self.win.resize(600, 400)
        self.win.setBackground(background='k')
        self.p1.setLabel(axis='left', text='Y')
        self.p1.setLabel(axis='bottom', text='X')
        self.p1.addLegend()
        self.curve1 = self.p1.plot(pen='y', name='yaw')
        self.curve2 = self.p1.plot(pen='g', name='pitch')

    def init_timer(self):
        self.timer = pg.QtCore.QTimer()
        self.timer.timeout.connect(self.plot_data)
        self.timer.start(100)

    def plot_data(self):
        self.curve1.setData(list(range(11)), [x * x for x in range(11)])
        if self.ptr == 0:
            # self.p1.disableAutoRange('xy')
            self.p1.enableAutoRange(axis='xy', enable=False, x=1, y=0.5)
            self.p1.disableAutoRange('xy')
        self.ptr += 1