Построение живых данных в цикле - PullRequest
0 голосов
/ 04 мая 2020

Я пытаюсь построить живые данные в Python (на данный момент Jupyter Notebook) с моего спектрометра, где я периодически получаю новые файлы, из которых я читаю температуру и насыщенность. Моя проблема в том, что с помощью FuncAnimation я получаю новый график каждый раз, когда получаю новый файл, но я хочу, чтобы он непрерывно отображался на одном и том же графике.

Temperature = []
Saturation = []
x_axis = [] #Placeholder for now, will soon be time
x = 0

def animate(i):
   plt.cla()
   plt.plot(x_axis, Temperature, label='Temperature')
   plt.plot(x_axis, Saturation, label='Saturation')

   plt.legend(loc='upper left')
   plt.tight_layout()

while True:
   while len(old_file) == len(new_file): #Loop for waiting for a new file in the folder
       time.sleep(1)
       new_file = glob.glob('Testspectrum/LivePlot/*')

   if len(old_file) != len(new_file):
       info = readout(new_file[-1]) #Readout is a function that returns the important information of the new file
       Temperature.append(info[3])
       Saturation.append(info[6]/200000)
       x = x+1
       x_axis.append(x)
       plt.cla()
       plt.tight_layout()
       plt.show()
       old_file = new_file

   ani = FuncAnimation(plt.gcf(), animate)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...