matplotlib embedded in tkinter

Solutions on MaxInterview for matplotlib embedded in tkinter by the best coders in the world

showing results for - "matplotlib embedded in tkinter"
Ryder
13 Jul 2017
1# Creates simple Graph embedded in tkinter
2
3import tkinter
4from tkinter import *
5import numpy as np
6from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
7from matplotlib.figure import Figure
8
9tkFenster = Tk()
10tkFenster.geometry('400x300')
11tkFenster.title('Simple Graph')
12
13figure = Figure(figsize=(4, 3), dpi=100)
14x = np.arange(-5, 5, .01)
15figure.add_subplot(111).plot(x, x**2)
16
17canvas = FigureCanvasTkAgg(figure, master=tkFenster)
18toolbar = NavigationToolbar2Tk(canvas, tkFenster)
19toolbar.update()
20canvas.draw()
21canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
22
23tkFenster.mainloop()