def main():
    maxlen = 500
    data_x = RingBuffer(maxlen,
                        datetime.datetime.utcnow(),
                        dtype=datetime.datetime)
    data_y = RingBuffer(maxlen)

    y = 100  # initial value

    fig, ax = plt.subplots()
    line, = ax.plot(data_x.all[::-1],
                    data_y.all[::-1],
                    linestyle='-',
                    marker='+',
                    color='r',
                    markeredgecolor='b')
    delta_y = 20
    ax.set_ylim([y - delta_y, y + delta_y])

    while True:
        x = datetime.datetime.utcnow()
        y = y + np.random.uniform(-1, 1)
        data_x.append(x)
        data_y.append(y)
        line.set_xdata(data_x.all[::-1])
        xmin, xmax = data_x.min(), data_x.max()
        if xmax > xmin:
            ax.set_xlim([xmin, xmax])
        line.set_ydata(data_y.all[::-1])
        ymin, ymax = data_y.min(), data_y.max()
        if ymax > ymin:
            ax.set_ylim([ymin, ymax])
        plt.pause(0.001)
Exemple #2
0
    def __init__(self, *args, **kwargs):
        super(MyApplication, self).__init__(*args, **kwargs)
        #self.t = QTime()
        #self.t.start()

        maxlen = 50
        self.data_x = RingBuffer(maxlen)
        self.data_y = RingBuffer(maxlen)

        self.win = pg.GraphicsWindow(title="Basic plotting examples")
        self.win.resize(1000, 600)
        self.win.setWindowTitle('Plot with PyQtGraph')

        self.plot = self.win.addPlot(title='Timed data', axisItems={'bottom': TimeAxisItem(orientation='bottom')})
        #self.plot.setYRange(0, 150)

        #self.curve = self.plot.plot()

        pen = pg.mkPen('r', style=QtCore.Qt.SolidLine)
        self.curve = self.plot.plot(pen=pen, symbol='+')

        self.timer = QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(100)

        self.y = 100
Exemple #3
0
def test_min_max():
    N = 5
    ring = RingBuffer(size_max=N, default_value=-1)
    ring.append(2)
    ring.append(1)
    ring.append(4)
    ring.append(3)
    assert ring.min() == 1
    assert ring.min(all=True) == -1
    assert ring.max() == 4
def main():
    maxlen = 50
    #data_x = RingBuffer(maxlen)
    data_y = RingBuffer(maxlen)

    y = 100  # initial value

    fig, ax = plt.subplots()
    line, = ax.plot(data_y.all[::-1])
    delta_y = 20
    ax.set_ylim([y - delta_y, y + delta_y])

    while True:
        y = y + np.random.uniform(-1, 1)
        data_y.append(y)
        line.set_ydata(data_y.all[::-1])
        plt.pause(0.001)
Exemple #5
0
    def __init__(self, win):
        #self.plot = pg.plot()
        self.plot = win.addPlot(title="Updating plot")

        self.ptr = 0

        #pen = 'r'
        pen = pg.mkPen('b', style=QtCore.Qt.SolidLine)
        self.curve = self.plot.plot(pen=pen, symbol='+')
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(50)

        self.value = 1000  # initial value
        N = 100  # number of elements into circular buffer

        self.data_y = RingBuffer(N, self.value)
Exemple #6
0
def test_ring():
    N = 10

    def print_overflow(*args, **kwargs):
        print("OVERFLOW of %s" % args[0])
        #raise NotImplementedError

    ring = RingBuffer(size_max=N,
                      default_value=0.0,
                      dtype=float,
                      overflow=print_overflow)
    for i in range(1, N + 5):
        ring.append(i)
        assert ring[0] == i
        if i < N:
            assert not ring.full
        else:
            assert ring.full

    assert isinstance(ring.all, np.ndarray)
    assert isinstance(ring.partial, np.ndarray)