Matplotlib动画嵌入Qt5 Gui中吗?

时间:2019-03-18 23:38:36

标签: python matplotlib

我正在使用Raspberry Pi 3B +和python 3.5.3。我正在使用ADS1115模数转换器从传感器获取一些值。

如何将这些代码嵌入Qt5 Gui?实际上,我没有在Qt5中嵌入matplotlib动画。

请帮助。

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn


x_len = 60        
y_range = [-5, 5]  

# Create figure for plotting
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
xs = list(range(0, 60))
ys = [0] * x_len
ax.set_ylim(y_range)


line, = ax.plot(xs, ys)


plt.title('ECG PLOTTING OVER TIME')
plt.xlabel('Time')
plt.ylabel('Voltage')


def animate(i, ys):
    i2c = busio.I2C(board.SCL, board.SDA,frequency=400000)
    ads = ADS.ADS1115(i2c,gain=2/3,data_rate=860)
    ads.data_rate=860
    chan = AnalogIn(ads, ADS.P0)



    ys.append(chan.voltage)


    ys = ys[-x_len:]


    line.set_ydata(ys)


    return line,

ani = animation.FuncAnimation(fig,animate,fargs=(ys,),interval=1,blit=True)
plt.show()

0 个答案:

没有答案