I don't have PyQt installed, so I couldn't test the code, but don't you
want to be using "extend" and not "append", if you are returning a list
from your two get_info() functions?
On Fri, Dec 2, 2011 at 8:13 AM, Fabien Lafont <lafont.fab...@gmail.com>wrote:
> Hello everyone, I'm trying to plot live data extracting from remote
> devices (here it's simulated by get_info1 and 2 the result is always
> 0.8 or 0.9
>
> I can't understand why it doesnt plot the graph at the end of the
> while loop. Does somebody has an idea?
>
> #!/usr/bin/env python
>
> from visa import *
> from pylab import *
> import sys
> from PyQt4 import QtGui
> import numpy as np
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
> FigureCanvas
> from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg
> as NavigationToolbar
>
>
> #===============================================================================
> #
>
> #===============================================================================
>
> class CPUMonitor(FigureCanvas):
> """Matplotlib Figure widget"""
> def __init__(self,parent):
>
> # first image setup
> self.fig = Figure()
> self.ax = self.fig.add_subplot(111)
> # initialization of the canvas
> FigureCanvas.__init__(self, self.fig)
> # set specific limits for X and Y axes
> self.ax.set_xlim(0, 2)
> self.ax.set_ylim(0, 1.5)
>
>
> # generates first "empty" plots
> self.user, self.nice = [], []
> self.l_user, = self.ax.plot([], self.user, label='Voltage')
> self.l_nice, = self.ax.plot([], self.nice, label='Voltage2')
>
>
>
> self.ax.legend()
>
> # force a redraw of the Figure
> self.fig.canvas.draw()
>
> self.principal()
>
>
>
>
> def principal(self) :
> stop = 0
> while stop==0 :
> time.sleep(1)
> self.set_voltage()
> time.sleep(1)
> result1 = self.get_info()
> result2 = self.get_info2()
>
> # append new data to the datasets
> self.user.append(result1)
> self.nice.append(result2)
>
> self.l_user.set_data(range(len(self.user)), self.user)
> self.l_nice.set_data(range(len(self.nice)), self.nice)
>
> # force a redraw of the Figure
>
> self.fig.canvas.draw()
> FigureCanvas.updateGeometry(self)
>
> def get_info(self):
> return [0.8]
>
> def get_info2(self) :
> return [0.9]
>
> def set_voltage(self) :
> print "ok"
>
>
>
>
>
> #===============================================================================
> #
>
> #===============================================================================
>
>
>
> class ApplicationWindow(QtGui.QMainWindow):
> """Example main window"""
> def __init__(self):
> # initialization of Qt MainWindow widget
> QtGui.QMainWindow.__init__(self)
> # set window title
> self.setWindowTitle("QHE manip")
> # instantiate a widget, it will be the main one
> self.main_widget = QtGui.QWidget(self)
> # create a vertical box layout widget
> vbl = QtGui.QVBoxLayout(self.main_widget)
> # instantiate our Matplotlib canvas widget
> qmc = CPUMonitor(self.main_widget)
> # instantiate the navigation toolbar
> ntb = NavigationToolbar(qmc, self.main_widget)
> # pack these widget into the vertical box
> vbl.addWidget(qmc)
> vbl.addWidget(ntb)
>
> # set the focus on the main widget
> self.main_widget.setFocus()
> # set the central widget of MainWindow to main_widget
> self.setCentralWidget(self.main_widget)
>
> # create the GUI application
> qApp = QtGui.QApplication(sys.argv)
> # instantiate the ApplicationWindow widget
> aw = ApplicationWindow()
> # show the widget
> aw.show()
> # start the Qt main loop execution, exiting from this script
> # with the same return code of Qt application
> sys.exit(qApp.exec_())
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure
> contains a definitive record of customers, application performance,
> security threats, fraudulent activity, and more. Splunk takes this
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
Daniel Hyams
dhy...@gmail.com
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users