0% found this document useful (0 votes)
11 views3 pages

GUI Python Part5

This document discusses plotting interactive matplotlib graphs on a tkinter canvas. It shows how to create a tkinter window with a matplotlib figure canvas, add a button to update the sinusoidal plot, and include an entry box to change the frequency. The document includes code examples to demonstrate interactive plotting of sinusoidal data in a tkinter GUI.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

GUI Python Part5

This document discusses plotting interactive matplotlib graphs on a tkinter canvas. It shows how to create a tkinter window with a matplotlib figure canvas, add a button to update the sinusoidal plot, and include an entry box to change the frequency. The document includes code examples to demonstrate interactive plotting of sinusoidal data in a tkinter GUI.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Slide 18 dari 18

Plotting matplotlib interaktif di canvas tkinter


import matplotlib as mpl utama = tk.Tk()
import numpy as np w = tk.Canvas(utama, width=600, height=500)
import tkinter as tk w.pack()
from matplotlib.backends.backend_tkagg import
FigureCanvasTkAgg canvas = FigureCanvasTkAgg(fig, master=w)
canvas.draw()
def update_plot(): canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH,
frek = float(input_frek.get()) expand=1)
y = 1 + np.sin(frek * 2 * np.pi * t)
ax.cla() # hapus yang lama # Buat tombol update frekuensi sinus
ax.plot(t, y, 'r-') tombol = tk.Button(utama, text="Update frekuensi",
ax.grid() command=update_plot)
canvas.draw() tombol.pack()
print("update")
# Buat entry frekuensi sinus
# Data for plotting input_frek = tk.Entry(utama, bd=5)
frek = 1 input_frek.insert(tk.END, '1')
t = np.arange(0.0, 2.0, 0.01) input_frek.pack()
y = 1 + np.sin(frek * 2 * np.pi * t)# sinus
utama.mainloop()
fig = mpl.figure.Figure(figsize = (6,5))
ax = fig.add_axes([0.1,0.1,0.85,0.85])
ax.plot(t, y, 'r-')
ax.grid()

Big Data Analytics Training Digitalent Kominfo – ITS (29 Okt 2018)
Hasilnya:
Slide 19 dari 18

Big Data Analytics Training Digitalent Kominfo – ITS (29 Okt 2018)
Tugas:
Slide 20 dari 18

• Buatlah GUI yang mampu menampilkan plot dari


data file CSV di komputer lokal memanfaatkan file
dialog box.
• Gunakan:
– tkinter: Canvas, filedialog, button
– pandas: read_csv
– matplotlib

Big Data Analytics Training Digitalent Kominfo – ITS (29 Okt 2018)

You might also like