Skip to content Skip to sidebar Skip to footer

Plotting Data From Generator In Python

Is there any plotting option in Python (IPython-Jupyter notebook) which accepts generators? AFAIK matplotlib doesn't support that. The only option I discovered is plot.ly with thei

Solution 1:

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

vals_list = list(vals_generator)

This should be appropriate input for 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 indata_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.

Post a Comment for "Plotting Data From Generator In Python"