Plotting in time using PyQtGraph and Pyserial
<p>I am trying to do a real-time plot, using pyqtgraph. I am reading the data, from and arduino, using Pyserial. I tried the matplotlib library before using pyqtgraph, but it did not gave me the speed that i need to plot. So, searching another ways to draw live-data, i met PyQtgraph. I read the docs and a lot of examples, and i have found these two examples:</p>

<p><a href="https://github.com/ap--/python-live-plotting/blob/master/plot_pyqtgraph.py" rel="nofollow">pltting with sample interval</a></p>

<p><a href="https://gist.github.com/friendzis/4e98ebe2cf29c0c2c232" rel="nofollow">plotting using pyqt4</a></p>

<p>Both are drawn as a function of time, which is what i need to do. I have modified each of them to get the data from the Arduino using Pyserial. The prolem is that it still draws very slow.</p>

<p>This is the code (from the second link) i am using:</p>

<pre><code>class TimeAxisItem(pg.AxisItem):
  def __init__(self, *args, **kwargs):
    super(TimeAxisItem, self).__init__(*args, **kwargs)

  def tickStrings(self, values, scale, spacing):
    return [QTime().addMSecs(value).toString('mm:ss') 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 = deque(maxlen=20)

    self.win = pg.GraphicsWindow(title="Basic plotting examples")
    self.win.resize(1000,600)

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

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

    print "Opening port"
    self.raw=serial.Serial("com4",9600)
    print "Port is open"


  def update(self):
    line = self.raw.read()
    ardString = map(ord, line)
    for number in ardString:
        numb = float(number/77.57)
        print numb
        self.data.append({'x': self.t.elapsed(), 'y': numb})
        x = [item['x'] for item in self.data]
        y = [item['y'] for item in self.data]
        self.curve.setData(x=x, y=y)

def main():
  app = MyApplication(sys.argv)
  sys.exit(app.exec_())

if __name__ == '__main__':
  main()
</code></pre>

<p>What can i do to draw faster over time?It seems that i am loosing some data with this code.</p>

<p>Really hope you can help me.</p>