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()
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Plplot-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/plplot-general