3

I want to export a pyqtgraph to a video. Is there any easy way to do this? The plot is not much different from this example except it contains about 10000 frames:

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg

app = QtGui.QApplication([])

win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
pg.setConfigOptions(antialias=True)
p6 = win.addPlot(title="0")
curve = p6.plot(pen='y')
data = np.random.normal(size=(10,1000))
ptr = 0
def update():
    global curve, data, ptr, p6
    data_ptr = ptr%10
    p6.setTitle("%d" % data_ptr)
    curve.setData(data[data_ptr])
    if ptr == 0:
        p6.enableAutoRange('xy', False)
    ptr += 1
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(50)
Joost
  • 1,426
  • 2
  • 16
  • 39

1 Answers1

2

Every frame is simply a single image. So you could use the imageexporter to generate an image for each of the frames. The toBytes argument of the export function will return the *.png file in memory, though you could also number them and save them in a temporary directory. An example of exporting the graph to a file is given in the pyqtgraph userguide.

You could then use ffmpeg to sequence them together.

If you went with the export to separate files option, you could use the ffmpeg command line as shown in: How to create a video from images with FFmpeg?

However, if you stored all frames in memory, the ffmpeg python bindings could be used for that, though I have no example for that.

Lanting
  • 3,060
  • 12
  • 28
  • 1
    Looks like your ImageExporter link is out of date: https://pyqtgraph.readthedocs.io/en/latest/user_guide/exporting.html – headdab Jan 16 '23 at 17:29
  • 1
    @headdab thanks, but it doesn't seem like a direct replacement. I can't seem to find proper documentation for the ImageExporter other than the source code. I'll update the answer with both a link to the new guide as well as to the source file. – Lanting Feb 03 '23 at 09:56