import numpy as np
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
  
app = QtGui.QApplication([])
mw = QtGui.QMainWindow()
mw.setWindowTitle('pyqtgraph example: ViewBox')
mw.show()
mw.resize(800, 600)

class Graph(QtCore.QObject):
    def __init__(self, parent=None):
        super(Graph, self).__init__(parent)

        self.gv = pg.GraphicsView()
        mw.setCentralWidget(self.gv)
        self.l = QtGui.QGraphicsGridLayout()
        self.l.setHorizontalSpacing(0)
        self.l.setVerticalSpacing(0)

        self.vb = pg.ViewBox()

        self.p1 = pg.PlotDataItem()
        self.vb.addItem(self.p1)
        self.l.addItem(self.vb, 0, 1)
        self.gv.centralWidget.setLayout(self.l)


        self.xScale = pg.AxisItem(orientation='bottom', linkView=self.vb)
        self.l.addItem(self.xScale, 1, 1)
        self.yScale = pg.AxisItem(orientation='left', linkView=self.vb)
        self.l.addItem(self.yScale, 0, 0)

        self.xScale.setLabel(text="<span style='color: #ff0000; font-weight: bold'>X</span> <i>Axis</i>", units="s")
        self.yScale.setLabel('Y Axis', units='V')

    def rand(self, n):
        data = np.random.random(n)
        data[int(n*0.1):int(n*0.13)] += .5
        data[int(n*0.18)] += 2
        data[int(n*0.1):int(n*0.13)] *= 5
        data[int(n*0.18)] *= 20
        return data, np.arange(n, n+len(data)) / float(n)

    def updateData(self):
        yd, xd = self.rand(10000)
        self.p1.setData(y=yd, x=xd)
        #self.vb.autoRange()

    #yd, xd = rand(10000)

g = Graph()
g.updateData()


t = QtCore.QTimer()
t.timeout.connect(g.updateData)
t.start(50)
  
    ## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()