title: Live plot sensor data Python Raspberry pi
body: <p>I have a BNO055 sensor connected to my Raspberry Pi via I2C protocol.
  This sensor can output 9 measurements including acceleration in all 3 axes.(x,y,z)</p>
  <p>I'd like to have a live plot of the x_acceleration as a function of time.</p>
  <p>I'm trying to run this code for a project on my Raspberry Pi.</p>
  <pre><code>def animate(i,t_updt,f,sp1,sensor1):
      initialtime = time.perf_counter()
      lastTime = initialtime;
      times=np.array([])
      x=np.array([])
      while(1): 
          currentTime = time.perf_counter()
          if  (currentTime - lastTime &gt;= 1/f):
              lastTime = currentTime
              times = np.append(times,lastTime - initialtime)
              sens1Acc = sensor1.acceleration     
              x = np.append(x,sens1Acc[0])       
          if len(times) == t_updt*f:
              break
      #Clear and draw new values   
      sp1.clear()
      sp1.plot(times,x)
      sp1.set_title('X - accel - sensor1')
      sp1.set_ylim([-10,10])
  </code></pre>
  <pre><code>import adafruit_bno055
  import time
  import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  import datetime as dt
  from busio import I2C
  from board import SDA, SCL
  from time import sleep
  
  ##Creating sensor1 object
  sensor1 = adafruit_bno055.BNO055_I2C(i2c,40)
  sensor1.mode = adafruit_bno055.NDOF_MODE
  sleep(2) # wait for system to stabilize
  
  f=50 #Sampling freq
  
  fig = plt.figure()
  sp1 = fig.add_subplot(1,1,1)       
  
  ani = animation.FuncAnimation(fig, animate, fargs=(5,f,sp1,sensor1),interval=1000)
  plt.show()
  
  
  </code></pre>
  <p>As you can see I've implemented my animate function which is being called every 1 sec.
  During the running of this function, there is a while loop that runs for 5 seconds(because of the fargs[0] argument passed ) , in which we sample 5 seconds of data at a rate of 50 hz.</p>
  <p>My only problem is:
  The graph plot doesn't update.
  I've printed out and saw that the x values do actually get updated, but the plot itself doesn't update...</p>
  <p>Any ideas?</p>