您可以在matplotlib中绘制实时数据吗?

您可以在matplotlib中绘制实时数据吗?,第1张

您可以在matplotlib中绘制实时数据吗?
import matplotlib.pyplot as pltimport timeimport threadingimport randomdata = []# This just simulates reading from a socket.def data_listener():    while True:        time.sleep(1)        data.append(random.random())if __name__ == '__main__':    thread = threading.Thread(target=data_listener)    thread.daemon = True    thread.start()    #    # initialize figure    plt.figure()     ln, = plt.plot([])    plt.ion()    plt.show()    while True:        plt.pause(1)        ln.set_xdata(range(len(data)))        ln.set_ydata(data)        plt.draw()

如果您想走得很快,则应考虑发li。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5646836.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存