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