|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +An example of how to use wx or wxagg in an application w/o the toolbar |
| 4 | +""" |
| 5 | + |
| 6 | +from matplotlib.numerix import arange, sin, pi |
| 7 | + |
| 8 | +import matplotlib |
| 9 | + |
| 10 | +# uncomment the following to use wx rather than wxagg |
| 11 | +#matplotlib.use('WX') |
| 12 | +#from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas |
| 13 | + |
| 14 | +# comment out the following to use wx rather than wxagg |
| 15 | +matplotlib.use('WXAgg') |
| 16 | +from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas |
| 17 | + |
| 18 | +from matplotlib.figure import Figure |
| 19 | + |
| 20 | +from wxPython.wx import * |
| 21 | + |
| 22 | +class CanvasFrame(wxFrame): |
| 23 | + |
| 24 | + def __init__(self): |
| 25 | + wxFrame.__init__(self,None,-1, |
| 26 | + 'CanvasFrame',size=(550,350)) |
| 27 | + |
| 28 | + self.SetBackgroundColour(wxNamedColor("WHITE")) |
| 29 | + |
| 30 | + self.figure = Figure(figsize=(5,4), dpi=100) |
| 31 | + self.axes = self.figure.add_subplot(111) |
| 32 | + t = arange(0.0,3.0,0.01) |
| 33 | + s = sin(2*pi*t) |
| 34 | + |
| 35 | + self.axes.plot(t,s) |
| 36 | + |
| 37 | + self.canvas = FigureCanvas(self, -1, self.figure) |
| 38 | + |
| 39 | + self.sizer = wxBoxSizer(wxVERTICAL) |
| 40 | + self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND) |
| 41 | + # Capture the paint message |
| 42 | + EVT_PAINT(self, self.OnPaint) |
| 43 | + |
| 44 | + def OnPaint(self, event): |
| 45 | + self.canvas.draw() |
| 46 | + |
| 47 | +class App(wxApp): |
| 48 | + |
| 49 | + def OnInit(self): |
| 50 | + 'Create the main window and insert the custom frame' |
| 51 | + frame = CanvasFrame() |
| 52 | + frame.Show(true) |
| 53 | + |
| 54 | + return true |
| 55 | + |
| 56 | +app = App(0) |
| 57 | +app.MainLoop() |
0 commit comments