tk and pyplot code example

Example: matplotlib embedded in tkinter

# Creates simple Graph embedded in tkinter

import tkinter
from tkinter import *
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure

tkFenster = Tk()
tkFenster.geometry('400x300')
tkFenster.title('Simple Graph')

figure = Figure(figsize=(4, 3), dpi=100)
x = np.arange(-5, 5, .01)
figure.add_subplot(111).plot(x, x**2)

canvas = FigureCanvasTkAgg(figure, master=tkFenster)
toolbar = NavigationToolbar2Tk(canvas, tkFenster)
toolbar.update()
canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)

tkFenster.mainloop()