Bonjour,

Je souhaite afficher une courbe pyplot dans un canvas.
Voici mon 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
 
from tkinter import *
import numpy as np
import matplotlib.pyplot as plt
 
a,b,c=0,0,0
 
def TracerGraphique():
  a=int(entryCoef1.get())
  b=int(entryCoef2.get())
  c=int(entryCoef3.get())
  x = np.linspace(-10, 10, 200)
  plt.plot(x, a*x**2+b*x+c)
  plt.show()
  plt.close()
 
fenetre=Tk()
fenetre.title("Polynome Second degré")
fenetre.geometry("700x250+150+50")
leftCanv = Canvas(fenetre, bg="blue", height=250, width=350)
leftCanv.pack(side=LEFT)
rightCanv = Canvas(fenetre, bg="yellow", height=250, width=350)
rightCanv.pack(side=RIGHT)
 
coef1=Label(leftCanv, text="donner coef x²: ", bg='yellow', fg='blue') #Affiche un text
coef2=Label(leftCanv, text="donner coef x: ", bg='yellow', fg='blue')
coef3=Label(leftCanv, text="Valeur de c : ", bg='yellow', fg='blue')
coef1.place(x=10, y=20)
coef2.place(x=10, y=50)
coef3.place(x=10, y=80)
entryCoef1=Entry(leftCanv)
entryCoef2=Entry(leftCanv)
entryCoef3=Entry(leftCanv)
entryCoef1.place(x=140, y=20)
entryCoef2.place(x=140, y=50)
entryCoef3.place(x=140, y=80)
 
boutonTracerGraphique=Button(leftCanv, text="Tracer graphique", font=("courrier",25), bg='yellow', fg='blue', command=TracerGraphique)
boutonTracerGraphique.place(x=10, y=170)
 
fenetre.mainloop()
Quand je clique sur le bouton, après avoir renseigner les les coefficient, ma courbe s'affiche dans une fenetre matplotlib alors que je veux qu'elle s'affiche dans le canvas de droite (le jaune)
Je sais que les couleurs sont mais c'est juste pour se repérer après tous sera uniforme
Toute aide est le bien venu
merci d'avance