From: Peter H. <pet...@sy...> - 2015-03-16 11:41:37
|
Dear all, I have recently started to try plplot to plot realtime data. I have extensively used matplotlib but found it for realtime much to slow. So I tried plplot and I got pretty fast nice results using plplot. I have anyhow a segfault problem with my python code and I do not fully understand why. What I experienced when e.g. applying the examples is that a resizing of the window does resizes the axes only when the window is resized according to the axes aspect ratio. So a resizing of the window in e.g. only the x-direction does not resize the plplot axes. What I found to work is that after a window resize you cleanup your existing plplot widgets ( calling plend(), plfreeqtdev() ) and start all over. This works quite well, but I get random segfaults. Attached is my python code, it should work out of the box. Any help is appreciated! Cheers, Peter # ------------------Snip----------------------- import sys import numpy as np import plplot # An indirect side effect of this import statement is a consistent set # of Qt4 libraries are loaded (e.g., if those are from some downloaded # non-system version in a non-standard location). import plplot_pyqt4 # This import statement must go after the one above to insure a # consistent set of Qt4 libraries are used for the case of the # downloaded, non-standard location of those libraries. from PyQt4 import QtCore, QtGui class plplot_Widget_test2(QtGui.QWidget): """ A plplot canvas widget """ def __init__(self,parent=None,numstream=0,pause=1,nsub=1): QtGui.QWidget.__init__(self) self.setParent(parent) self.nsub = nsub self.x_data = [] self.y_data = [] self.x_all = [] self.y_all = [] self.init = True def plplotInit(self): if(self.init): width = 200 height = 200 self.init = False else: width = self.frameSize().width() height = self.frameSize().height() print "Init",width,height # PLplot setup self.plot = plplot_pyqt4.QtExtWidget(width, height, self) plplot_pyqt4.plsetqtdev(self.plot) plplot.plsdev("extqt") plplot.plinit() self.plplotinitAxes() print "End plotinitaxes" def plplotstartTimer(self): print "Timer" self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.plplotupdatePlot) self.timer.start(200) print "Timer end" def plplotinitAxes(self): print "initAxes" colbox = 1 collab = 3 styline = [2, 3, 4, 5] colline = [2, 3, 4, 5] legline = ["1", "2", "3", "4"] xlab = 0. ylab = 0.25 # legend position autoy = 1 # autoscale y acc = 1 # don t scrip, accumulate self.id = [] # Register our error variables with PLplot # From here on, we're handling all errors here if(self.nsub>1): plplot.plssub(2, 2) for i in range(self.nsub): plplot.pladv(0) plplot.plvsta() tmin = 0 tmax = 10 tjump = .3 ymin = -.10 ymax = .10 print "New Axes!" id = plplot.plstripc("bcnst", "bcnstv", tmin, tmax, tjump, ymin, ymax, xlab, ylab, autoy, acc, colbox, collab, colline, styline, legline, "Hello!", "", "Strip chart demo") self.id.append(id) print "End New Axes!" self.update() def plplotupdatePlot(self): if(len(self.x_data)>0): print "Update plot 1",self.x_data while(len(self.x_data)>0): x = self.x_data.pop(0) y = self.y_data.pop(0) self.x_all.append(x) self.y_all.append(y) for i in range(self.nsub): plplot.pladv(i+1) plplot.plstripa(self.id[i], 0, x, y) self.update() def plplotCleanup(self): print "Cleanup" self.timer.stop() plplot.plend() plplot_pyqt4.plfreeqtdev() print "End Cleanup" def resizeEvent(self, event): self.plplotCleanup() self.plplotInit() self.plplotstartTimer() class QPlot(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self, None) self.resize(300,300) self.lw = QtGui.QWidget(self) self.l = QtGui.QVBoxLayout(self.lw) self.lw1 = plplot_Widget_test2(self,nsub=4) self.l.addWidget(self.lw1) self.lw1.plplotInit() self.lw1.plplotstartTimer() self.setCentralWidget(self.lw) print "Init random data generator" timer = QtCore.QTimer(self) timer.timeout.connect(self.data_gen) timer.start(250) self.n = 0 def data_gen(self): self.n += 1 self.lw1.x_data.append(self.n * 0.1) self.lw1.y_data.append(np.random.rand(1)[0]) app = QtGui.QApplication(sys.argv) plot = QPlot() plot.show() app.exec_() plot.lw1.plplotCleanup() |
From: Alan W. I. <ir...@be...> - 2015-03-16 19:12:28
|
On 2015-03-16 12:41+0100 Peter Holtermann wrote: > Dear all, > > > I have recently started to try plplot to plot realtime data. I have > extensively used matplotlib but found it for realtime much to slow. So I > tried plplot and I got pretty fast nice results using plplot. > I have anyhow a segfault problem with my python code and I do not fully > understand why. > > > What I experienced when e.g. applying the examples is that a resizing of > the window does resizes the axes only when the window is resized > according to the axes aspect ratio. So a resizing of the window in e.g. > only the x-direction does not resize the plplot axes. > > > What I found to work is that after a window resize you cleanup your > existing plplot widgets ( calling plend(), plfreeqtdev() ) and start all > over. This works quite well, but I get random segfaults. Attached is my > python code, it should work out of the box. > > > Any help is appreciated! Hi Peter: Thanks for your interest in PLplot. I am glad to hear it is faster than matplotlib, but sorry to hear that you are running into segfaults for your test of our pyqt4 binding. We take memory management errors (which often produce segfaults) seriously. However, it may be a long process to sort out this issue, but to help get that debug process started, I and others do test our pyqt4 binding via examples/python/pyqt4_example.py (e.g., by using the cmake option -DBUILD_TEST=ON, and after cmake is completed running make test_pyqt4_example in the build tree or as part of some larger test such as make test_interactive in the build tree. We run such tests routinely as part of due diligence leading up to releases, and so far nobody has reported segfaults with that example. Of course, that is a "for what it is worth" comment because memory management errors sometimes don't lead to segfaults or any other obvious symptom, and also because pyqt4_example.py is a simpler test for our pyqt4 binding than your test case. Nevetheless, you should do that same test yourself just to make sure you can replicate our good test result for this case. Your post caught my eye because you mentioned resizing. That typically uses plbuf capabilities, and a number of bug fixes have just been completed for plbuf. So just now for the git master tip version of PLplot I ran the test_pyqt4_example target above and did a lot of resizing of the resulting GUI without segfault (or other) issues, and you might want to try the same thing. Also, I suggest you try that test and also your own example using the git master tip version of PLplot just in case the recent plbuf fixes have solved the segfault problem for you. And more about that master tip version in my next post. Alan __________________________ Alan W. Irwin Astronomical research affiliation with Department of Physics and Astronomy, University of Victoria (astrowww.phys.uvic.ca). Programming affiliations with the FreeEOS equation-of-state implementation for stellar interiors (freeeos.sf.net); the Time Ephemerides project (timeephem.sf.net); PLplot scientific plotting software package (plplot.sf.net); the libLASi project (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project (lbproject.sf.net). __________________________ Linux-powered Science __________________________ |
From: Peter H. <pet...@sy...> - 2015-03-17 19:49:00
|
Hi Alan, I have used the debian out of the box version 5.1.0. I will try to reproduce (hopefully not though) the segfaults with the latest git release. Maybe its already fixed with the plbuf changes ... I will report the results then! Cheers, Peter > > > We take memory management errors (which often produce segfaults) > seriously. However, it may be a long process to sort out this issue, > but to help get that debug process started, I and others do test our > pyqt4 binding via examples/python/pyqt4_example.py (e.g., by using the > cmake option -DBUILD_TEST=ON, and after cmake is completed running > > make test_pyqt4_example > > in the build tree or as part of some larger test such as > > make test_interactive > > in the build tree. > > We run such tests routinely as part of due diligence leading up to > releases, and so far nobody has reported segfaults with that example. > Of course, that is a "for what it is worth" comment because memory > management errors sometimes don't lead to segfaults or any other > obvious symptom, and also because pyqt4_example.py is a simpler test > for our pyqt4 binding than your test case. Nevetheless, you should do > that same test yourself just to make sure you can replicate our good > test result for this case. > > Your post caught my eye because you mentioned resizing. That > typically uses plbuf capabilities, and a number of bug fixes have just > been completed for plbuf. So just now for the git master tip version > of PLplot I ran the test_pyqt4_example target above and did a lot of > resizing of the resulting GUI without segfault (or other) issues, and > you might want to try the same thing. > > Also, I suggest you try that test and also your own example using the > git master tip version of PLplot just in case the recent plbuf fixes > have solved the segfault problem for you. > > And more about that master tip version in my next post. > > Alan > __________________________ > Alan W. Irwin > > Astronomical research affiliation with Department of Physics and Astronomy, > University of Victoria (astrowww.phys.uvic.ca). > > Programming affiliations with the FreeEOS equation-of-state > implementation for stellar interiors (freeeos.sf.net); the Time > Ephemerides project (timeephem.sf.net); PLplot scientific plotting > software package (plplot.sf.net); the libLASi project > (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net); > and the Linux Brochure Project (lbproject.sf.net). > __________________________ > > Linux-powered Science > __________________________ |