1
votes

I am trying to move from matplotlib to plotting with pyqtgraph because of its touted capabilities to render and save images faster. In my attempts to do this on a cluster with multiprocessors, I run into the following trouble:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-user' qt.qpa.screen: QXcbConnection: Could not connect to display Could not connect to any X display.

How do I obviate displaying a plot, and save it directly to file? Here's my attempt at the code:

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import pyqtgraph.exporters

#app = QtGui.QApplication([])
#view = pg.GraphicsView()
l = pg.GraphicsWindow()
#view.setCentralItem(l)
#view.show()
#view.setWindowTitle('GraphicsLayout')
#view.resize(1000,1600)


def plotlayout(lines):
    p_res={}
    p_data={}
    for rows in rows:
        p_res[row]={}
        p_data[row]={}       
        for col in cols:
            l2=l.addLayout()
            p_res[row][col]=l2.addPlot()
            p_res[row][col].hideAxis('bottom')
            l2.nextRow()
            p_data[row][col]=l2.addPlot()
            l.nextColumn()
        l.nextRow()
    return p_res, p_data    
pl = plotlayout(lines) 
pl[0].plot([1,3,5,9,7,8],[2,3,3,5,6,8])                
pl[1].plot([1,3,5,9,7,8],[2,22,3,45,6,8])
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
        QtGui.QApplication.exit()
        QtGui.QApplication.quit()
        QtGui.QApplication.quitOnLastWindowClosed()
        QtGui.QApplication.closeAllWindows()
exporter = pg.exporters.ImageExporter(l.scene())
exporter.export('fits.ps')

I have tested this on my personal laptop and it works fine.

1
Where have you installed pyqtgraph? What is your OS? What is your desktop environment? Do you have PyQt5 installed? - eyllanesc
uncomment this line #app = QtGui.QApplication([]) - eyllanesc
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: RedHatEnterpriseServer Description: Red Hat Enterprise Linux Server release 6.10 (Santiago) Release: 6.10 Codename: Santiago ; I've installed using conda. Yes, PyQt5 is installed. - Sameeresque
Do you have a window manager or desktop system? How do you connect to your server: do you use SSH or some other protocol? - eyllanesc

1 Answers

1
votes

If you want to run a GUI without using desktop environment/window manager a possible solution is to use Xvfb.