Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Python + PyQt] ajustement taille axes

Sujet résolu
    15 novembre 2011 à 14:30:27

    Bonjour,

    J'ai un petit problème. j'ai écrit un programme sous python qui doit afficher sous forme d'une courbe des données. Ici c'est simplement 0.8 et 0.9 et cela ne change pas. Le problème est que je n'arrive pas redimensionner mes axes afin de voir tout mon graphe. Pourtant j'utilise bien self.ax.set_autoscale_on(True) mais rien ne s'ajuste. Avez vous une idée?


    #!/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 to display CPU utilization"""
        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)
            
    
           
            #self.ax.set_autoscale_on(True)
    
            # 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()
    
            # initialize the iteration counter
            self.cnt = 0
            
            # call the update method (to speed-up visualization)
            self.timerEvent(None)
    
            # start the timer, to trigger an event every x milliseconds)
            self.timer = self.startTimer(100)
            
           
        def get_info(self):
                   
            return [0.8]
    	 
        def get_info2(self):
    	
            return [0.9]
    
        def timerEvent(self, evt):
            # get the value from the device
         
            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_())
    
    • Partager sur Facebook
    • Partager sur Twitter

    [Python + PyQt] ajustement taille axes

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown