Menu

[r5932]: / trunk / users_guide / code / embedding_gtk.py  Maximize  Restore  History

Download this file

45 lines (35 with data), 1.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
from matplotlib.numerix import arange, sin, pi
import matplotlib # specify your
matplotlib.use('GTKAgg') # backend
import matplotlib.backends as backend
from backend.backend_gtkagg \
import FigureCanvasGTKAgg
from matplotlib.backends.backend_gtk \
import NavigationToolbar2GTK
from matplotlib.figure import Figure
import gtk
# set up your native GUI window
win = gtk.Window()
win.show()
win.connect("destroy", gtk.mainquit)
vbox = gtk.VBox(spacing=3)
vbox.show()
win.add(vbox)
# create a matplotlib figure - backend independent
# code here
fig = Figure()
ax = fig.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
ax.plot(t,s)
# the FigureCanvas classes are imbeddable in your GUI
# FigureCanvasGTKAgg derives from gtk.DrawingArea
canvas = FigureCanvasGTKAgg(fig)
canvas.show()
vbox.pack_start(canvas)
# you can build a custom toolbar
toolbar = NavigationToolbar2GTK(canvas)
toolbar.show()
vbox.pack_start(toolbar, gtk.FALSE, gtk.FALSE)
gtk.main()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.