2017-12-26 3 views
1

dies ist meine erste Frage Beitrag.Python> Matplotlib> Animierte Live-Handlung> Framerate

Ich sehe eine Wiederholungsrate von etwa 1 Bild alle 5 Sekunden in meinem Live-Plot mit dem untenstehenden Code. Ich möchte etwas sehen, das den Echtzeit-Updates nahe kommt. Die serielle Rate der geplotteten Daten reicht aus, um mindestens 2 Frames pro Sekunde zu unterstützen.

Ich habe dieses einfache Skript anhand von Beispielen erstellt, die ich auf dieser Site gefunden habe, und habe einige Fragen zur erneuten Anwendung dieser Beispiele gelesen.

Ich bin kein häufiger/erfahrener Coder.

import serial #import pyserial library 

ser=serial.Serial('/dev/tty.usbmodem14611', baudrate = 9600, timeout=1) #set serial COM port, baud, [timeout if you are using a while loop] 
my_list = [] # define a list to hold each data point as it comes in 
count_list = [] # define a list to hold the x axis data point (in our case we will grab the computer time stamp of each data point) 

import matplotlib.pyplot as plt #import the matplot library 
import matplotlib.animation as animation #define the matplotlib animation function object 
import time #import the python time library 

fig = plt.figure() #define a figure object 
ax1 = fig.add_subplot(1,1,1) #add a subplot to the figure, you can add more subplots for additional data types if desired 

xar = [] #define a list to hold the new x dimension of plot on each update 
yar = [] #define a list to hold the new y dimension of plot on each update 

def animate(i): #define an animation function 

    arduinoData = ser.readline().decode('ascii') #read current data on serial monitor, decode as ascii data type 
    Data = arduinoData.split() #split each word/text block into a temporary list named Data 
    if len(Data) > 2: #check if Data has at least 3 words/text blocks 
     if Data[0]=='Yaw,': #check if position 0 in the temporary list Data is equal to "Yaw," 

      p=Data[3] #set variable p equal to position 3 of the list Data 
      s = p.replace(',', '') #set variable s equal to variable p, after removing the comma 
      yar.append(float(s)) 
      print(float(s)) 

      #millis = int(round(time.time() * 1000)) #grab current EPOCH time of loop from local pc 
      xtime = time.time() 
      xar.append(xtime) 



    ax1.clear() #clear previous axis data 
    ax1.plot(xar,yar) #plot updated axis data for xar and yar lists 

ani = animation.FuncAnimation(fig, animate, interval=1) #call the animation function with an interval of ? millis 
plt.show() #show plot in gui 
+0

Ich habe die Antwort auf meine Frage @ https://Stackoverflow.com/a/40749129 gefunden –

Antwort