0
votes

At the moment I am using matplotlib to plot multiple numpy arrays (or lists) of data. These correspond to approximately 3000 plots. The plots are time series. My problem is that when these lists become too large with a lot of data, matplotlib is very slow. I read that pyqtgraph can plot really fast, but my question is:

Can you use pyqtgraph to plot data without spawning that pyqt window and instead directly save them to files? Matplotlib had an option to change backend so it does not spawn the window but instead just create the file, is there something similar for pyqtgraph?

Also do you think that, for my problem, pyqtgraph is the correct way to go? I see it a lot for plotting streaming data live, but what I want to do does not involve live stream data. Should I use something else to create plots for all my data?

2
what do you mean by: directly save them to files? - eyllanesc
So, when pyqtgraph plots something it spawns a window and shows you the data plotted in x and y axis. What i want is to not create this window, and just save the image that would have been shown in that window to a file. Since i have a lot of plots that i want to create and i also want to save the final image files, spawning this window is not really an option for me. - Ploo
You have many questions, and you must know that SO is a place of a question per post, so the button to create says Ask Question, does not say Ask Questions. - eyllanesc
Maybe you have not understand correctly what i am asking. My question is one, and is: Can pyqtgraph create multiple plots without using the spawned window? - Ploo
Okay, now I understand, you could show a simple example of how you do it in matplotlib and I'll use that example to do it in pyqtgraph ;P - eyllanesc

2 Answers

2
votes

You do not need to show a window if you want to save an image of the plot, the following in an example:

import pyqtgraph as pg
import pyqtgraph.exporters

plt = pg.plot([1, 2, 3, 4, 5], [2, 5, 2, 5, 2])
exporter = pg.exporters.ImageExporter(plt.plotItem)
exporter.parameters()['width'] = 640
exporter.export('fileName.png')

Although that library has a bug, the solution is simple, you must go to the file pyqtgraph/exporters/ImageExporter.py

pyqtgraph
|
...
├── exporters
│   ├── ...
│   ├── ImageExporter.py
... ...

and change line 70 of:

bg = np.empty((self.params['width'], self.params['height'], 4), dtype=np.ubyte)

to:

bg = np.empty((int(self.params['width']), int(self.params['height']), 4), dtype=np.ubyte)

fileName.png

enter image description here

References:

0
votes

To close the window that opens by default, you could add plt.win.close() as seen below:

import pyqtgraph as pg
import pyqtgraph.exporters

plt = pg.plot([1, 4, 3, 9, 5], [2, 3, 2, 1, 0])
plt.win.close()
exporter = pg.exporters.ImageExporter(plt.plotItem)
exporter.parameters()['width'] = 640
exporter.export('fileName.png')

References: http://www.pyqtgraph.org/documentation/exporting.html