What I have tried is this
import sys
> import numpy as np
> import datetime
>
> from PyQt4.QtCore import QTime, QTimer
> from pyqtgraph.Qt import QtGui, QtCore
> import pyqtgraph as pg
>
> from collections import deque
>
> import pytz
> UNIX_EPOCH_naive = datetime.datetime(1970, 1, 1, 0, 0) #offset-naive datetime
> UNIX_EPOCH_offset_aware = datetime.datetime(1970, 1, 1, 0, 0, tzinfo =
> pytz.utc) #offset-aware datetime
> UNIX_EPOCH = UNIX_EPOCH_naive
>
> TS_MULT_us = 1e6
>
> class RectangleItem(pg.GraphicsObject):
> def __init__(self, topLeft, size):
> pg.GraphicsObject.__init__(self)
> self.topLeft = topLeft
> self.size = size
> self.generatePicture()
>
> def generatePicture(self):
> self.picture = QtGui.QPicture()
> p = QtGui.QPainter(self.picture)
> p.setPen(pg.mkPen('w'))
> tl = QtCore.QPointF(self.topLeft[0], self.topLeft[1])
> size = QtCore.QSizeF(self.size[0], self.size[1])
> p.drawRect(QtCore.QRectF(tl, size))
> p.end()
>
> def paint(self, p, *args):
> p.drawPicture(0, 0, self.picture)
>
> def boundingRect(self):
> return QtCore.QRectF(self.picture.boundingRect())
>
>
> def now_timestamp(ts_mult=TS_MULT_us, epoch=UNIX_EPOCH):
> return(int((datetime.datetime.utcnow() - epoch).total_seconds()*ts_mult))
>
> def int2dt(ts, ts_mult=TS_MULT_us):
> return(datetime.datetime.utcfromtimestamp(float(ts)/ts_mult))
>
> def dt2int(dt, ts_mult=TS_MULT_us, epoch=UNIX_EPOCH):
> delta = dt - epoch
> return(int(delta.total_seconds()*ts_mult))
>
> def td2int(td, ts_mult=TS_MULT_us):
> return(int(td.total_seconds()*ts_mult))
>
> def int2td(ts, ts_mult=TS_MULT_us):
> return(datetime.timedelta(seconds=float(ts)/ts_mult))
>
> class TimeAxisItem(pg.AxisItem):
> def __init__(self, *args, **kwargs):
> # super().__init__(*args, **kwargs)
> super(TimeAxisItem, self).__init__(*args, **kwargs)
>
> def tickStrings(self, values, scale, spacing):
> # PySide's QTime() initialiser fails miserably and dismisses
> args/kwargs
> #return [QTime().addMSecs(now_timestamp()).toString('mm:ss') for
> value in values]
> return [int2dt(value).strftime("%H:%M:%S.%f") for value in values]
>
>
>
> class MyApplication(QtGui.QApplication):
> def __init__(self, *args, **kwargs):
> super(MyApplication, self).__init__(*args, **kwargs)
> self.t = QTime()
> self.t.start()
> self.data=[]
>
> #maxlen = 20
> self.data_x = deque()
> self.data_y = deque()
>
> self.win = pg.GraphicsWindow(title="Basic plotting examples")
> self.win.resize(1000,600)
>
> tai = TimeAxisItem(orientation='bottom')
> self.plot = self.win.addPlot(title='Timed data', axisItems={'bottom':
> TimeAxisItem(orientation='bottom')})
> #self.plot.setYRange(0, 150)
> self.curve = self.plot.plot()
>
> self.tmr = QTimer()
> self.tmr.timeout.connect(self.update)
> self.tmr.start(100)
>
> self.y = 100
>
> def update(self):
> self.data.append({'x': self.t.elapsed(), 'y': np.random.randint(0,
> 100)})
> x = now_timestamp()
> self.y = self.y + np.random.uniform(-1, 1)
>
> self.data_x.append(x)
> self.data_y.append(self.y)
> self.curve.setData(x=list(self.data_x), y=list(self.data_y))
> self.plotui = pg.PlotWidget()
>
> item2 = RectangleItem([x,x+2], [self.y, self.y+2])
> self.plotui.addItem(item2)
>
> def main():
> app = MyApplication(sys.argv)
> sys.exit(app.exec_())
>
> if __name__ == '__main__':
> main()
>
>
But it is not showing
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/44b4866a-2547-41f2-8be0-dd4b37b31246%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.