2

As a continuation of this question of mine: pyqtgraph for plotting multiple data lists

I managed to use pyqtgraph to export my plot to a file. But i still get the window that pyqtgraph spawns in order to try to create the plot there. This window now shows nothing, it is empty and white. When i use regular python console, after a while this window disappears, but if i use Ipython, the window says "Not responding" and when i close it Ipython says "Kernel died, restarting".

Is there a way to completely disable this pyqtgraph window and only use the output file to create the plot, in order for it to work correctly without errors?

I used to do this with matplotlib (which had the same window popping up, but if you used command matplotlib.use('Agg'), to change the backend, then the window stopped popping.

1 Answer 1

2

Oh my... i just figured it out! My first answer on SO, don't be too harsh on me.

First, make sure you are creating your pyqtgraph graph in a constructor(init function) of a class. Call it there once and immediately hide it (that was the complicated part for me).

Here is an example code:

import numpy as np
import pyqtgraph as pg
import pyqtgraph.exporters


class MyPlotClass():
    def __init__(self):
        self.windowplt = pg.plot()
        self.windowplt.win.hide()

    def savePlots(self):
        x = np.arange(0, 256)
        y = np.arange(0, 256)
        self.windowplt.plot(x, y)
        exporter = pg.exporters.ImageExporter(self.windowplt.plotItem)
        exporter.params.param('width').setValue(256, blockSignal=exporter.widthChanged)
        exporter.params.param('height').setValue(256, blockSignal=exporter.heightChanged)
        for i in np.arange(0,10):
            exporter.export('./fileName' + str(i) +  '.png')
            print(i)

if __name__ == "__main__":
    saveMyFiles = MyPlotClass()
    saveMyFiles.savePlots()

Only one window WILL appear for a shot duration and hide itself immediately. I know your Question is old, but it might help anyone in the future. I was searching for the solution for the whole day now.

As mentioned in your previous thread pyqtgraph for plotting multiple data lists the ImageExporter.py bug still exists. Insted of changing the code of the pyqtgraph library you can work around it by setting both width and height yourself (as in the code above).

exporter.params.param('width').setValue(256, blockSignal=exporter.widthChanged)
exporter.params.param('height').setValue(256, blockSignal=exporter.heightChanged)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.