I'm using an example from Sandro's Tosi book. I've just modified it to
use random data instead cpu_datas.

But the autoscale doesn't work even if I turn
self.ax.set_autoscale_on(True). Do you have an Idea why?




from pylab import *
import random

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)
       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')
       self.ax.set_autoscale_on(True)

       # 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):
       val1 = random.randint(0,4)
       return [val1]

   def get_info2(self) :
       val2 = random.randint(0,12)
       return [val2]

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

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to