IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PyQt Python Discussion :

Autoscale graphe matplotlib


Sujet :

PyQt Python

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Inscrit en
    Novembre 2011
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2011
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Autoscale graphe matplotlib
    Bonjour,

    J'ai un petit problème. j'ai adapté un programme sous python qui doit afficher sous forme d'une courbe des données. Ici c'est simplement 0.9 et 0.8 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?


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    #!/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_())

  2. #2
    Rédacteur/Modérateur

    Avatar de Jiyuu
    Homme Profil pro
    Développeur amateur
    Inscrit en
    Janvier 2007
    Messages
    2 456
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur amateur
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 2 456
    Points : 6 789
    Points
    6 789
    Billets dans le blog
    15
    Par défaut


    A priori ton problème ne relève pas trop de Qt directement, mais de matplotlib.

    Ne connaissant pas du tout cette librairie, je ne peux t'aider dessus.
    Par contre, juste au cas où, Qt permet peut être de faire ce que tu cherches sans passer par une tierce librairie.

    En fouillant rapidement, j'ai trouvé ceci.
    http://www.developpez.net/forums/d99...tracer-courbe/

    Cela peut peut être t'aider à reconsidérer ton besoin et donc la solution...

    Bonne continuation.
    Initiation à Qt Quick et QML : Partie 1 - Partie 2
    En cas de besoin, pensez à la
    Mon site et mes tutoriaux sur Developpez.com
    Pas de question technique par MP... Les forums sont là pour ça

Discussions similaires

  1. Polar graph - Matplotlib
    Par Julien N dans le forum Calcul scientifique
    Réponses: 0
    Dernier message: 12/02/2013, 11h58
  2. Réponses: 3
    Dernier message: 31/10/2012, 17h01
  3. autoscale avec matplotlib
    Par Invité dans le forum Général Python
    Réponses: 1
    Dernier message: 12/10/2009, 20h40
  4. Enregistrer un graph Matplotlib
    Par Dramac dans le forum Calcul scientifique
    Réponses: 2
    Dernier message: 08/04/2009, 16h00
  5. [matplotlib] dessiner graph avec pcolor
    Par thibaultG dans le forum Calcul scientifique
    Réponses: 3
    Dernier message: 02/04/2008, 08h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo