หนึ่งในกรณีการใช้งานที่รู้จักกันดีของ Python คือการเรียนรู้ด้วยเครื่องและวิทยาศาสตร์ข้อมูล เพื่อให้เห็นภาพและพล็อตชุดข้อมูล เราใช้ไลบรารี Matplotlib ในการพล็อตกราฟ matplotlib ในแอปพลิเคชัน Tkinter เราต้องนำเข้าไลบรารีโดยเริ่มต้น "จาก matplotlib.pyplot เป็น plt " พล็อตสามารถวาดได้โดยการกำหนดค่าช่วงหรือนำเข้าชุดข้อมูลในสมุดบันทึก
ตัวอย่าง
#Import the required Libraries
from tkinter import *
from tkinter import ttk
import numpy as np
import matplotlib.pyplot as plt
#Create an instance of Tkinter frame
win= Tk()
#Set the geometry of the window
win.geometry("700x250")
def graph():
car_prices= np.random.normal(50000,4000,2000)
plt.figure(figsize=(7,3))
plt.hist(car_prices, 25)
plt.show()
#Create a Button to plot the graph
button= ttk.Button(win, text= "Graph", command= graph)
button.pack()
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างที่มีปุ่ม

เมื่อเราคลิกปุ่ม "กราฟ" ก็จะแสดงกราฟบนหน้าต่างหลัก
