实时绘制动态频谱图

时间:2020-09-09 19:18:43

标签: python numpy matplotlib spectrogram vispy

我基本上在三个独立的numpy数组中具有三个数据点,我想沿x轴绘制时间,沿y轴绘制频率,并且幅度应代表颜色。但这一切都是实时发生的,因此它看起来像频谱图在数据更新时正在吸引自己。

我简化了代码,以表明我正在运行一个循环,该循环最多需要10毫秒才能运行,在这段时间内,我从函数中获取新数据。

import numpy as np
import random
from time import sleep

def new_val_freq():
   return random.randint(0,22)

def new_val_mag():
   return random.randint(100,220)

x_axis_time = np.array([1])
y_axis_frequency = np.array([10])
z_axis_magnitude = np.array([100])

t = 1
while True:
   x_axis_time = np.append (x_axis_time , [t+1])
   t+=1

   y_axis_frequency = np.append (y_axis_frequency , [new_val_freq()])
   z_axis_magnitude = np.append (z_axis_magnitude, [new_val_mag()])
   
   time.sleep(0.01)
   #Trying to figure out how Create/Update spectrogram plot with above additional 
   #data in real time without lag

理想情况下,我希望此过程尽可能快,而不必重新绘制整个频谱图。似乎matplolib不适合绘制动态频谱图,而且我还没有遇到任何动态频谱图示例,所以我想知道如何做到这一点?

0 个答案:

没有答案
相关问题