Bonjour,
j'ai créé une IHM via QtDesigner incluant un widget QTableWidget (nommé "tableValeurs") et un widget MatplotlibWidget (nommé "matplotlibWidget").
Je souhaite afficher des lignes dans ce widget mais la figure reste vide, rien ne s'affiche...
Voici mon code:
Je ne maîtrise pas encore très bien matplotlib, en tout cas je ne vois pas ce qui cloche et pourquoi mes lignes ne s'affichent pas!
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 import sys, os from PyQt4 import QtGui from PyQt4 import QtCore from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas import matplotlib.pyplot as plt import IHM.IHM_MaFenetre class MaFenetre(QtGui.QDialog, IHM.IHM_MaFenetre.Ui_MaFenetre): def __init__(self, parent=None): ''' Constructeur de MaFenetre ''' # Initialisation de l'IHM super(MaFenetre, self).__init__() self.ui = IHM.IHM_MaFenetre.Ui_MaFenetre() self.ui.setupUi(self) # Initialisation du matplotlib widget self.ui.matplotlibWidget.figure = plt.Figure(facecolor='white') self.ui.matplotlibWidget.canvas = FigureCanvas(self.ui.matplotlibWidget.figure) self.ui.matplotlibWidget.axes = self.ui.matplotlibWidget.figure.add_subplot(111) # Le SLOT "updateGraphe" est appelé lorsque l'utilisateur modifie une valeur dans le QTableWidget self.ui.tableValeurs.cellChanged.connect(self.updateGraphe) def updateGraphe(self): ''' Mise a jour du graphe en fonction des valeurs du tableau Ici avec des valeurs fixes pour test ''' # Reinitialisation du graphe self.ui.matplotlibWidget.axes.cla() self.ui.matplotlibWidget.axes.hold(True) # Dessin des lignes hlineLarg = self.ui.matplotlibWidget.axes.axhline(y=0, xmin=1, xmax = 2) hlineMid = self.ui.matplotlibWidget.axes.axhline(y=0.5, xmin=2, xmax = 3) hlineEcart = self.ui.matplotlibWidget.axes.axhline(y=1, xmin=3, xmax = 4) self.ui.matplotlibWidget.axes.add_artist(hlineLarg) self.ui.matplotlibWidget.axes.add_artist(hlineMid) self.ui.matplotlibWidget.axes.add_artist(hlineEcart) # Affichage du graphe self.ui.matplotlibWidget.canvas.draw()
Merci d'avance pour votre aide.
Partager