title: Fast plotting data in python
body: <p>I'm trying to plot data from mpu6050 imu with arduino. MPU6050 sends data faster than plot. Arduino code gives 6 data which are yaw, pitch, roll, ax,ay and az from serial port. I need suggestions for fast plot .</p>
  
  <p>Python Code:</p>
  
  <pre><code>import serial
  import matplotlib.pyplot as plt #import matplotlib library
  from drawnow import * 
  
  ser = serial.Serial('COM9', 115200)
  yaw = 0.0
  pitch =0.0
  roll =0.0
  ax =0.0
  ay =0.0
  az =0.0
  o_yaw= [0]
  o_pitch= [0]
  o_roll= [0]
  o_ax= [0]
  o_ay= [0]
  o_az= [0]
  plt.ion()
  cnt=0
  def makeFig(): 
      plt.ylim(-1000,1000)                                 
      plt.grid(True)
      plt.ylabel('Magnitude')  
      plt.plot(olculen_ax, 'ro-', label='ax') 
      plt.plot(olculen_ay, 'bo-', label='ay')  
      plt.plot(olculen_az, 'go-', label='az')                               
      plt.legend()                    
  while True:
      incoming=ser.readline()
      if ("hand" in incoming):
          incoming=incoming.split(":")
          if len(incoming)==8:
              yaw = float(incoming[1])
              pitch = float(incoming[2])
              roll = float(incoming[3])
              ax = float(incoming[4])
              ay = float(incoming[5])
              az = float(incoming[6])
              print "Split works"
      else:
          print incoming
      o_ax.append(ax)                    
      o_ay.append(ay)    
      o_az.append(az)
      o_yaw.append(yaw)
      o_pitch.append(pitch)
      o_roll.append(roll)              
  
      drawnow(makeFig)                       
      plt.pause(.00001)                     
      cnt=cnt+1
      if(cnt&gt;50):                            
          o_ax.pop(0)
          o_ay.pop(0)                     
          o_az.pop(0)
  </code></pre>
  
  <p>Arduino Code (I just add loop. code derived from <a href="https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/Examples/MPU6050_DMP6/MPU6050_DMP6.ino" rel="nofollow">this</a>):</p>
  
  <pre><code>void loop() {
      if (!dmpReady) return;
      while (!mpuInterrupt &amp;&amp; fifoCount &lt; packetSize) {
      }
  
      mpuInterrupt = false;
      mpuIntStatus = mpu.getIntStatus();
  
      fifoCount = mpu.getFIFOCount();
  
       if ((mpuIntStatus &amp; 0x10) || fifoCount == 1024) {
      mpu.resetFIFO();
      //Serial.println(F("FIFO overflow!"));
  } else if (mpuIntStatus &amp; 0x02) {
      while (fifoCount &lt; packetSize) fifoCount = mpu.getFIFOCount();
      mpu.getFIFOBytes(fifoBuffer, packetSize);
      fifoCount -= packetSize;
      mpu.dmpGetQuaternion(&amp;q, fifoBuffer);
      mpu.dmpGetAccel(&amp;aa, fifoBuffer);
      mpu.dmpGetGravity(&amp;gravity, &amp;q);
      mpu.dmpGetLinearAccel(&amp;aaReal, &amp;aa, &amp;gravity);
      mpu.dmpGetLinearAccelInWorld(&amp;aaWorld, &amp;aaReal, &amp;q);
      mpu.dmpGetYawPitchRoll(ypr, &amp;q, &amp;gravity);
      Serial.print("hand:");
      Serial.print(ypr[0] * 180/M_PI);
      Serial.print(":");
      Serial.print(ypr[1] * 180/M_PI);
      Serial.print(":");
      Serial.print(ypr[2] * 180/M_PI);
      Serial.print(":");
      Serial.print(aaWorld.x);
      Serial.print(":");
      Serial.print(aaWorld.y);
      Serial.print(":");
      Serial.print(aaWorld.z);
      Serial.println(":");
  }
  
  }
  </code></pre>