File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from matplotlib .numerix import arange , sin , pi
2+
3+ import matplotlib
4+ matplotlib .use ('TkAgg' )
5+
6+ from matplotlib .axes import Subplot
7+ from matplotlib .backends .backend_tkagg import FigureCanvasTkAgg
8+ from matplotlib .figure import Figure
9+
10+ import Tkinter as Tk
11+ import sys
12+
13+ def destroy (e ): sys .exit ()
14+
15+ root = Tk .Tk ()
16+ root .wm_title ("Embedding in TK" )
17+ root .bind ("<Destroy>" , destroy )
18+
19+
20+ f = Figure (figsize = (5 ,4 ), dpi = 100 )
21+ a = Subplot (f , 111 )
22+ t = arange (0.0 ,3.0 ,0.01 )
23+ s = sin (2 * pi * t )
24+
25+ a .plot (t ,s )
26+ f .add_axis (a )
27+
28+ canvas = FigureCanvasTkAgg (f , master = root ) # a tk.DrawingArea
29+ canvas .show ()
30+ canvas .get_tk_widget ().pack (side = Tk .TOP )
31+
32+ button = Tk .Button (master = root , text = 'Quit' , command = sys .exit )
33+ button .pack (side = Tk .BOTTOM )
34+
35+ Tk .mainloop ()
You can’t perform that action at this time.
0 commit comments