Thx all for your remarks,

I can't understand why this code works (when I use the timer method):

# -*- coding: utf-8 -*-
"""
Created on Fri Dec 02 17:10:22 2011

@author: lafont
"""

#!/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, 40)
#        self.ax.set_ylim(0, 1.5)


#
        FigureCanvas.updateGeometry(self)
        # 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')


        # add legend to plot
        self.ax.legend()

        # force a redraw of the Figure
        self.fig.canvas.draw()




        # start the timer, to trigger an event every x milliseconds)
        self.timer = self.startTimer(1000)
        self.timerEvent(None)


    def get_info(self):
        return [0.8]
        
    def get_info2(self) :
        return [0.9]

    def set_voltage(self) :
        print "ok"






#

    def timerEvent(self, evt):
        """Custom timerEvent code, called upon timer event receive"""
        result1 = self.get_info()
        result2 = self.get_info2()

#          append new data to the datasets
        self.user.append(result1)
        self.nice.append(result2)
        # update lines data using the lists with new data
        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)



#===============================================================================
#
#===============================================================================



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_())









And this code doesn't show anything... Somebody understand why?

Thanks,

Fabien





2011/12/4 David Hoese <dho...@gmail.com>
>
> I think you forget to set the layout on your central widget.
>
> self.main_widget.setLayout(vbl) # in your case
>
> -Dave
>
> On 12/4/2011 9:57 AM, matplotlib-users-requ...@lists.sourceforge.net wrote:
> > 2011/12/2 Daniel Hyams<dhy...@gmail.com>:
> >> >  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?
>
> ------------------------------------------------------------------------------
> 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

------------------------------------------------------------------------------
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

Reply via email to