Hi Vasilije, Many thanks for your solution - it works well!
I understand that qapp = pg.mkQApp() initializes the application but not too sure about the precise meaning of sys.exit(qapp.exec_()). Also how would these commands change if I were using them within classes. Finally, I realize that as the 'matrix_main' array size increases over time, the plot would take up more and more RAM memory. Is there anyway to improve this situation (e.g. calling garbage collection) - I guess that with 'curve1.setData', previous trace is already being deleted before new one is plotted. Many thanks for your help. On Friday, 5 August 2016 18:06:38 UTC+1, [email protected] wrote: > > Hi All, > > I have recently started using Python and pyqtgraph so apologies for a > rather basic question. I am trying to read some data from a file and plot > it using pyqtgraph (as given in the code below). All the plot > initialization is done in the main function and then the plot is updated > through a QTimer. However, when I try to run this code, it returns the > error: > > QtGui.QApplication.instance().exec_() > AttributeError: 'NoneType' object has no attribute 'exec_' > > Any help with this would be much appreciated. > > Thanks. > > import multiprocessing > import numpy as np > import sys > import pyqtgraph as pg > from pyqtgraph.Qt import QtCore, QtGui > import ReadData > > def main(): > matrix_main = np.memmap('myData.dat', dtype='float64', mode='w+', > shape=(5000, 5)) > > p = multiprocessing.Process(target=ReadData.worker) > p.start() > > win1 = pg.GraphicsWindow() > win1.setWindowTitle('Data plot') > > p1 = win1.addPlot() > > index = int(matrix_main[0, 0]) > curve1 = p1.plot(matrix_main[:index, 2], pen='k') > pg.QtGui.QApplication.processEvents() > timer = pg.QtCore.QTimer() > timer.timeout.connect(update1) > timer.start(1000) > > def update1(): > global curve1, matrix_main > index = int(matrix_main[0, 0]) > curve1.setData(matrix_main[:index, 2]) > > if __name__ == '__main__': > if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): > QtGui.QApplication.instance().exec_() > main() > > > > -- You received this message because you are subscribed to the Google Groups "pyqtgraph" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/2d72f103-5c74-43f9-be71-b8ceb8d06329%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
