I'm running some basic code from the documentation
import pyqtgraph as pg
import numpy as np
x = np.arange(1000)
y = np.random.normal(size=(3, 1000))
plotWidget = pg.plot(title="Three plot curves")
for i in range(3):
plotWidget.plot(x, y[i], pen=(i,3))
But for some reason the window open then closes straight away, i just see a flicker of it. Is there some sort of function in which i can keep the window open?
You can keep the window open by creating a QApplication
at the beginning of the script and then calling its exec_()
method at the end of your script, like this:
import pyqtgraph as pg
import numpy as np
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv) # Create QApplication ***
x = np.arange(1000)
y = np.random.normal(size=(3, 1000))
plotWidget = pg.plot(title="Three plot curves")
for i in range(3):
plotWidget.plot(x, y[i], pen=(i, 3))
# Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_() # Start QApplication event loop ***
I put *** on the key lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With