Bonjour,
j'ai réalisé le programme suivant :
Je le lance via une interface graphique en pyQt4 (voir code ci-dessous):
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 import sys, fpformat, os, random, time sys.path.append("C:\\Python26\\Lib\\site-packages") import numpy as np from scipy.interpolate import griddata import matplotlib.pyplot as plt import numpy.ma as ma from numpy.random import uniform, seed import numpy from numpy import * import pylab as p import mpl_toolkits.mplot3d.axes3d as p3 from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter def Carte_erreur_3D_surf(): try: os.remove('graph température 3D.png') except: pass x=[] y=[] z=[] Fichier = 'C:\\Temp\\donnees image defaut nettoye.txt' # pour traiter les température Table=numpy.loadtxt(Fichier) Table=array(Table) for i in range((len(Table))): x.append(Table[i][0]) # coord x y.append(Table[i][1]) # coord y z.append(Table[i][2]) # carte de température A=Table[0][0] B=Table[0][1] C=Table[len(Table)-1][0] D=Table[len(Table)-1][1] E=Table[0][2] F=Table[len(Table)-1][2] x=array(x) y=array(y) z=array(z) # u and v are parametric variables. # u is an array from 0 to 2*pi, with 100 elements u=r_[0:2*pi:len(Table)] # v is an array from 0 to 2*pi, with 100 elements v=r_[0:2*pi:len(Table)] # x, y, and z are the coordinates of the points for plotting # each is arranged in a 100x100 array xi = np.linspace(A,C,len(Table)) yi = np.linspace(B,D,len(Table)) zi = griddata((x, y), z, (xi[None,:], yi[:,None]), method='cubic') fig=p.figure() ax = p3.Axes3D(fig) xi, yi, zi = p3.get_test_data(0.05) surf = ax.plot_surface(xi, yi, zi, rstride=8, cstride=8, alpha=0.3, cmap= plt.cm.jet) ax.set_xlabel('X') ax.set_xlim3d(A,C) ax.set_ylabel('Y') ax.set_ylim3d(B,D) ax.set_zlabel('Carte de temperature') ax.set_zlim3d(E, F) ax.w_zaxis.set_major_locator(LinearLocator(10)) ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f')) p.colorbar(surf, shrink=0.5, aspect=5) p.show()
J'ai une erreur que je ne comprends 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
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 import sys,os from Tkinter import * import tkFileDialog from PyQt4 import QtCore, QtGui from Carte_defaut import * from Traitements_image import * from fileopen import * h = 300 l = 400 class Frame(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) self.resize(l,h) self.setFont(QtGui.QFont("Verdana")) self.setWindowTitle("Traitement données thermographie IR") try: self.setWindowIcon(QtGui.Icon("icon.jpg")) except:pass fen = QtGui.QDesktopWidget().screenGeometry() size = self.geometry() self.move((fen.width()-size.width())/2, (fen.height()-size.height())/2) #Création de la barre de statut avec les informations voulues. self.statusBar().showMessage("Identification de la taille des défauts") menubar = self.menuBar() ## Création d'une barre de menu file_ = menubar.addMenu("Fichier") ## Ajout d'un menu. #Ajout de la fenêtre Ã* onglets self.tabWidget = QtGui.QTabWidget(self) self.tabWidget.setGeometry(0,20,l,h-40) #Création de deux QWidget qui permettront ensuite de créer les pages du QTabWidget self.pnl_1 = QtGui.QWidget(self.tabWidget) #Ajout des QWidgets en temps que Tab du QTabWidget. #Le premier Tab portera le nom Entrée et le deuxième le nom Lecture. self.tabWidget.addTab(self.pnl_1, "Courbe d'erreurs") #Modification de la couleur de fond des QWidget. self.pnl_1.setPalette(QtGui.QPalette(QtGui.QColor("white"))) self.pnl_1.setAutoFillBackground(True) self.gene = QtGui.QPushButton("Carte temperature 2D (couleur)", self.pnl_1) self.gene.move(110, 25) self.gene.clicked.connect(Carte_erreur_C) self.gene = QtGui.QPushButton("Carte temperature 2D (niveau de gris)", self.pnl_1) self.gene.move(110, 75) self.gene.clicked.connect(Carte_erreur_NB) self.gene = QtGui.QPushButton("Carte temperature 3D (points)", self.pnl_1) self.gene.move(110, 150) self.gene.clicked.connect(Carte_erreur_3D_P) self.gene = QtGui.QPushButton("Carte temperature 3D (surface)", self.pnl_1) self.gene.move(110, 200) self.gene.clicked.connect(Carte_erreur_3D_surf) if __name__ == '__main__': app = QtGui.QApplication(sys.argv) frame = Frame() frame.show() sys.exit(app.exec_())
Est ce que quelqu'un pourrait m'éclairer car ça fait 2 jours que j'y passe dessus et je ne comprends toujours pas d'où cela peut venir.
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 Exception in Tkinter callback Traceback (most recent call last): File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__ return self.func(*args) File "C:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 212, in resize self.show() File "C:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 215, in draw FigureCanvasAgg.draw(self) File "C:\Python26\lib\site-packages\matplotlib\backends\backend_agg.py", line 314, in draw self.figure.draw(self.renderer) File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 46, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 773, in draw for a in self.axes: a.draw(renderer) File "C:\Python26\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 151, in draw self.w_zaxis.draw(renderer) File "C:\Python26\lib\site-packages\mpl_toolkits\mplot3d\axis3d.py", line 220, in draw newval = get_flip_min_max(xyz1[0], newindex, mins, maxs) IndexError: list index out of range
Merci d'avance.
Cordialement.
Partager