Menu

[r384]: / trunk / htdocs / examples / embedding_in_wx2.py  Maximize  Restore  History

Download this file

58 lines (39 with data), 1.5 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
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
"""
An example of how to use wx or wxagg in an application w/o the toolbar
"""
from matplotlib.numerix import arange, sin, pi
import matplotlib
# uncomment the following to use wx rather than wxagg
#matplotlib.use('WX')
#from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
# comment out the following to use wx rather than wxagg
matplotlib.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
from wxPython.wx import *
class CanvasFrame(wxFrame):
def __init__(self):
wxFrame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))
self.SetBackgroundColour(wxNamedColor("WHITE"))
self.figure = Figure(figsize=(5,4), dpi=100)
self.axes = self.figure.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
self.axes.plot(t,s)
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wxBoxSizer(wxVERTICAL)
self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND)
# Capture the paint message
EVT_PAINT(self, self.OnPaint)
def OnPaint(self, event):
self.canvas.draw()
class App(wxApp):
def OnInit(self):
'Create the main window and insert the custom frame'
frame = CanvasFrame()
frame.Show(true)
return true
app = App(0)
app.MainLoop()
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.