在Python中绘制来自生成器的数据 [英] Plotting data from generator in Python

查看:56
本文介绍了在Python中绘制来自生成器的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python(IPython-Jupyter笔记本)中是否有任何接受生成器的绘图选项?

Is there any plotting option in Python (IPython-Jupyter notebook) which accepts generators?

AFAIK matplotlib不支持该功能.我发现的唯一选择是使用其Streaming API的 plot.ly ,但由于数量众多,我不希望使用在线解决方案我需要实时绘制的数据.

AFAIK matplotlib doesn't support that. The only option I discovered is plot.ly with their Streaming API, but I would prefer not to use online solution due to big amount of data I need to plot in real-time.

推荐答案

固定长度的生成器始终可以转换为列表.

A fixed length generator can always be converted to a list.

vals_list = list(vals_generator)

这应该是matplotlib的适当输入.

根据您的更新信息,可能是这样的:

Guessing from your updated information, it might be something like this:

from collections import deque
from matplotlib import pyplot

data_buffer = deque(maxlen=100)
for raw_data in data_stream:
  data_buffer.append(arbitrary_convert_func(raw_data))
  pyplot.plot(data_buffer)

基本上使用双端队列来固定大小的数据点缓冲区.

Basically using a deque to have a fixed size buffer of data points.

这篇关于在Python中绘制来自生成器的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆