Bonjour, je suis un gros néophite donc je m'excuse d'avance si mes questions ne sont pas précise.

J'essaye de coder un programme qui trace des courbes parametré, on lui donne x(t),y(t) et possiblement z(t) et il trace la courbe.

Je pense m'en etre pas trop mal sortie pour l'instant, mais il y a deux problème qui depasse totalement ma compréhension :
(i) quand je trace un certain nombre de figure je recois le message d'erreur suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 C:\Users\GALLO\Documents\module1.py:122: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
   fig,ax=plt.subplots()
(ii) Quand je trace la courbe dans R3 avec matplotlib je peux la faire "tourner"(en cliquant et en bougeant la souris), mais quand je l'affiche dans mon application avec kivy, je ne peux plus interagir avec la figure, quelqu'un sait si il y a une solution ?

Je vous met la fonction dans la quelle se trouve surments les problèmes :

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
    def Drawing3(self):
        #affiche la courbe
        T=True
        #Tracer de la courbe
        t=sp.Symbol('t')
        x=self.xvalue.text
        y=self.yvalue.text
        z=self.zvalue.text
        if x!='' and y!='' and z!='':
            tm=self.tmin.text
            tM=self.tmax.text
            XX=sp.lambdify(t,eval(x),'numpy')
            YY=sp.lambdify(t,eval(y),'numpy')
            ZZ=sp.lambdify(t,eval(z),"numpy")
            t_=np.linspace(eval(tm),eval(tM),5000)
            fig=plt.figure()
            ax=fig.gca(projection='3d')
            ax.plot(XX(t_),YY(t_),ZZ(t_),color='k')
            ax.set_xlabel('x')
            ax.set_ylabel('y')
            ax.set_zlabel('z')
            left,right=plt.xlim()
            bottom,top=plt.ylim()
            self.graphique=FigureCanvasKivyAgg(fig)
            self.graphique.use_parent_modelview=True
            self.graph.clear_widgets()
            self.graph.add_widget(self.graphique)


Et voici l'intégralité du code :

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
 
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib
matplotlib.use("module://kivy.garden.matplotlib.backend_kivy")
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
 
import numpy as np
 
from sympy import cos,sin,exp,sqrt,pi
import sympy as sp
 
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.image import Image
from kivy.uix.checkbox import CheckBox
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.properties import ObjectProperty
 
 
 
 
Window.size=(1200,500)
Window.left=100
Window.top=100
class WindowManager(ScreenManager):
    pass
 
class ScreenMenu(Screen):
    pass
 
class ScreenCourbe3D(Screen):
 
    tmin=ObjectProperty(None)
    tmax=ObjectProperty(None)
    xvalue=ObjectProperty(None)
    yvalue=ObjectProperty(None)
    graph=ObjectProperty(None)
    cbdevelopante=ObjectProperty(None)
    save_file_name=ObjectProperty(None)
 
    def Drawing3(self):
        #affiche la courbe
        T=True
        #Tracer de la courbe
        t=sp.Symbol('t')
        x=self.xvalue.text
        y=self.yvalue.text
        z=self.zvalue.text
        if x!='' and y!='' and z!='':
            tm=self.tmin.text
            tM=self.tmax.text
            XX=sp.lambdify(t,eval(x),'numpy')
            YY=sp.lambdify(t,eval(y),'numpy')
            ZZ=sp.lambdify(t,eval(z),"numpy")
            t_=np.linspace(eval(tm),eval(tM),5000)
            fig=plt.figure()
            ax=fig.gca(projection='3d')
            ax.plot(XX(t_),YY(t_),ZZ(t_),color='k')
            ax.set_xlabel('x')
            ax.set_ylabel('y')
            ax.set_zlabel('z')
            left,right=plt.xlim()
            bottom,top=plt.ylim()
            self.graphique=FigureCanvasKivyAgg(fig)
            self.graphique.use_parent_modelview=True
            self.graph.clear_widgets()
            self.graph.add_widget(self.graphique)
 
 
    def Savefile(self):
        self.graphique.print_png(self.save_file_name.text)
 
 
 
class ScreenEDO(Screen):
    pass
 
class ScreenCourbe2D(Screen):
    tmin=ObjectProperty(None)
    tmax=ObjectProperty(None)
    xvalue=ObjectProperty(None)
    yvalue=ObjectProperty(None)
    graph=ObjectProperty(None)
    cbdevelopante=ObjectProperty(None)
    save_file_name=ObjectProperty(None)
 
 
    def Drawing(self):
        #affiche la courbe
        T=True
        #Tracer de la courbe
        t=sp.Symbol('t')
        x=self.xvalue.text
        y=self.yvalue.text
        if x!='' and y!='':
            tm=self.tmin.text
            tM=self.tmax.text
            XX=sp.lambdify(t,eval(x),'numpy')
            YY=sp.lambdify(t,eval(y),'numpy')
            t_=np.linspace(eval(tm),eval(tM),5000)
            fig,ax=plt.subplots()
            ax.plot(XX(t_),YY(t_),color='k')
            ax.set_xlabel('x')
            ax.set_ylabel('y')
            left,right=plt.xlim()
            bottom,top=plt.ylim()
            self.graphique=FigureCanvasKivyAgg(fig)
            self.graph.clear_widgets()
            self.graph.add_widget(self.graphique)
            #Tracer de la devellopant
            if self.cbdevelopante.active:
                dotX=sp.lambdify(t,sp.diff(eval(x),t),'numpy')
                dotY=sp.lambdify(t,sp.diff(eval(y),t),'numpy')
                ddotX=sp.lambdify(t,sp.diff(eval(x),t,t),'numpy')
                ddotY=sp.lambdify(t,sp.diff(eval(y),t,t),'numpy')
                Norme=lambda s :np.sqrt(dotX(s)**2+dotY(s)**2)
                det=lambda s:dotX(s)*ddotY(s)-dotY(s)*ddotX(s)
                R=lambda s:Norme(s)**3/det(s)
                CX=lambda s:(XX(s)-Norme(s)**2*dotY(s)/det(s))
                CY=lambda s:(YY(s)+Norme(s)**2*dotX(s)/det(s))
                plt.xlim(left,right)
                plt.ylim(bottom,top)
                ax.plot(CX(t_),CY(t_),label='Devellopante',color='r')
 
    def Savefile(self):
        self.graphique.print_png(self.save_file_name.text)
 
   ############################################
 
 
 
kv=Builder.load_string("""
 
WindowManager :
    ScreenMenu
    ScreenCourbe2D
    ScreenCourbe3D
    ScreenEDO
 
<ScreenMenu>:
    name :'Menu'
    BoxLayout:
        size_hint:(0.8,0.8)
        pos_hint:{'center_x':0.5,'center_y':0.5}
        orientation:'vertical'
        BoxLayout:
            size_hint:(0.7,0.4)
            pos_hint:{'center_x':0.5,'center_y':0.1}
            orientation:'vertical'
            Image:
                source:'Plotthis.jpg'
 
        BoxLayout:
            size_hint:(0.4,0.7)
            pos_hint:{'center_x':0.5,'center_y':0.45}
            orientation:'vertical'
 
            Button:
                text:'Courbe en 2D'
                on_press: root.manager.current='Courbe2D'
                background_normal:'fondbouton.png'
            Button:
                text:'Courbe en 3D'
                on_press: root.manager.current='Courbe3D'
                background_normal:'fondbouton.png'
 
            Button:
                text:'Equation différentiel'
                on_press: root.manager.current='EDO'
                background_normal:'fondbouton.png'
 
            Button:
                text:'Quitter'
                on_press: app.get_running_app().stop()
                background_normal:'fondbouton.png'
 
<ScreenCourbe2D>:
    xvalue:xvalue
    yvalue:yvalue
    tmin:tmin
    tmax:tmax
    graph:graph
    cbdevelopante:cbdevelopante
    save_file_name:save_file_name
 
 
    name : 'Courbe2D'
    size_hint_min: (1000,500)
 
    BoxLayout:
        orientation : 'horizontal'
        BoxLayout:
            orientation:'vertical'
            width:250
            size_hint_x:None
            GridLayout:
                cols:2
                size_hint_y:0.2
 
                Label:
                    text:'X(t)='
                    width:30
                    size_hint_x:None
                TextInput:
                    id:xvalue
                    multiline:False
                    write_tab:False
 
                Label:
                    text:'Y(t)='
                    width:30
                    size_hint_x:None
                TextInput:
                    id:yvalue
                    multiline:False
                    write_tab:False
 
            GridLayout:
                cols:4
                size_hint_y:0.10
                Label:
                    text:'tmin='
                TextInput:
                    id:tmin
                    multiline:False
                    write_tab:False
                Label:
                    text:'tmax='
                TextInput:
                    id:tmax
                    multiline:False
                    write_tab:False
 
            GridLayout:
                cols:4
                size_hint_y:0.2
 
                CheckBox:
                    id:cbdevelopante
                Label:
                    text:'devellopante'
 
            Button:
                text:"Draw"
                size_hint:(0.3,0.1)
                pos_hint:{'center_x':0.5,'center_y':0.5}
                on_press: root.Drawing()
 
            GridLayout:
                cols:2
 
            GridLayout:
                cols:2
                size_hint_y:0.10
                TextInput:
                    id:save_file_name
                    multiline:False
                    write_tab:False
                    text:'.jpg'
                Button:
                    text:"SAVE"
                    on_press:root.Savefile()
 
 
        BoxLayout:
            id:graph
            size_hint_min: (0.7,1)
            Image:
 
                source:'Plotthis.jpg'
    Button:
        text:'Back'
        size_hint:(0.07,0.04)
        pos_hint:{'center_x':0.95,'center_y':0.03}
        on_press:root.manager.current='Menu'
 
 
 
<ScreenCourbe3D>:
 
    xvalue:xvalue
    yvalue:yvalue
    zvalue:zvalue
    tmin:tmin
    tmax:tmax
    graph:graph
    save_file_name:save_file_name
 
 
    name : 'Courbe3D'
    size_hint_min: (1000,500)
 
    BoxLayout:
        orientation : 'horizontal'
        BoxLayout:
            orientation:'vertical'
            width:250
            size_hint_x:None
            GridLayout:
                cols:2
                size_hint_y:0.3
 
                Label:
                    text:'X(t)='
                    width:30
                    size_hint_x:None
                TextInput:
                    id:xvalue
                    multiline:False
                    write_tab:False
 
                Label:
                    text:'Y(t)='
                    width:30
                    size_hint_x:None
                TextInput:
                    id:yvalue
                    multiline:False
                    write_tab:False
 
                Label:
                    text:'Z(t)='
                    width:30
                    size_hint_x:None
                TextInput:
                    id:zvalue
                    multiline:False
                    write_tab:False
 
            GridLayout:
                cols:4
                size_hint_y:0.10
                Label:
                    text:'tmin='
                TextInput:
                    id:tmin
                    multiline:False
                    write_tab:False
                Label:
                    text:'tmax='
                TextInput:
                    id:tmax
                    multiline:False
                    write_tab:False
 
            GridLayout:
                cols:4
                size_hint_y:0.2
 
 
            Button:
                text:"Draw"
                size_hint:(0.3,0.1)
                pos_hint:{'center_x':0.5,'center_y':0.5}
                on_press: root.Drawing3()
 
            GridLayout:
                cols:2
 
            GridLayout:
                cols:2
                size_hint_y:0.10
                TextInput:
                    id:save_file_name
                    multiline:False
                    write_tab:False
                    text:'.jpg'
                Button:
                    text:"SAVE"
                    on_press:root.Savefile()
 
 
        BoxLayout:
            id:graph
            size_hint_min: (0.7,1)
            Image:
                source:'Plotthis.jpg'
 
    Button:
        text:'Back'
        size_hint:(0.07,0.04)
        pos_hint:{'center_x':0.95,'center_y':0.03}
        on_press:root.manager.current='Menu'
 
<ScreenEDO>:
    name:"EDO"
 
""")
 
 
 
 
class CourbePA(App):
    def build(self):
        return kv
 
 
if __name__=="__main__":
    CourbePA().run()

Merci beaucoup ! et bonne journée