在 Python 中绘制生成器的数据

Plotting data from generator in Python

Python(IPython-Jupyter notebook)中是否有接受生成器的绘图选项?

AFAIK matplotlib 不支持。我发现的唯一选择是 plot.ly 和他们的 Streaming API,但我不想使用在线解决方案,因为我需要实时绘制大量数据。

定长生成器始终可以转换为列表。

vals_list = list(vals_generator)

这应该是适合 matplotlib 的输入。


根据你更新的信息推测,可能是这样的:

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)

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