[Boa Constr] Re: how to create graph and table using matplotlib
Status: Beta
Brought to you by:
riaan
From: Werner F. B. <wer...@fr...> - 2005-03-31 07:46:40
|
Hi Jan, You create a class based on e.g. wx.Panel and then you can use it in Boa by defining it as a custom_class. Have a look in "boa\Examples\advanced\CustomClasses". See you Werner jrlen balane wrote: > sorry for being noob, but what is customclass > > > > On Tue, 22 Feb 2005 10:56:42 +0100, Werner F. Bruhin > <wer...@fr...> wrote: > >>Hi jrlen, >> >>What about using a wxPanel to hold the matplotlib stuff (instead of the >>wxFrame used in the sample below) and then you could use it as a >>customclass in Boa and add the panel to your wxFrame1. >> >>See you >>Werner >> >> >>jrlen balane wrote: >> >>>i understand that there is an existing example in matplotlib that >>>teaches how to embed matplotlib to wxpython. >>>what i want to know is how to do this in BOA. where to put the codes >>>from the example specifically. >>>for example i create new wxApp, with a new wxFrame, now here is the >>>code from the demo: >>> >>>======================================================= >>>#!/usr/bin/env python >>># embedding_in_wx.py >>># >>> >>>""" >>>Copyright (C) Jeremy O'Donoghue, 2003 >>> >>>License: This work is licensed under the PSF. A copy should be included >>>with this source code, and is also available at >>>http://www.python.org/psf/license.html >>> >>>This is a sample showing how to embed a matplotlib figure in a wxPanel. >>> >>>The example implements the full navigation toolbar, so you can automatically >>>inherit standard matplotlib features such as the ability to zoom, pan and >>>save figures in the supported formats. >>> >>>There are a few small complexities worth noting in the example: >>> >>>1) By default, a wxFrame can contain a toolbar (added with SetToolBar()) >>> but this is at the top of the frame. Matplotlib default is to put the >>> controls at the bottom of the frame, so you have to manage the toolbar >>> yourself. I have done this by putting the figure and toolbar into a >>> sizer, but this means that you need to override GetToolBar for your >>> wxFrame so that the figure manager can find the toolbar. >>> >>>2) I have implemented a figure manager to look after the plots and axes. >>> If you don't want a toolbar, it is simpler to add the figure directly >>> and not worry. However, the figure manager looks after clipping of the >>> figure contents, so you will need it if you want to navigate >>> >>>3) There is a bug in the way in which my copy of wxPython calculates >>> toolbar width on Win32, so there is a tricky line to ensure that the >>> width of the toolbat is the same as the width of the figure. >>> >>>4) Depending on the parameters you pass to the sizer, you can make the >>> figure resizable or not. >>>""" >>> >>>import matplotlib >>>matplotlib.use('WX') >>>from matplotlib.backends.backend_wx import Toolbar, FigureCanvasWx,\ >>> FigureManager >>> >>>from matplotlib.figure import Figure >>>from matplotlib.axes import Subplot >>>import matplotlib.numerix as numpy >>>from wxPython.wx import * >>> >>> >>> >>>class PlotFigure(wxFrame): >>> def __init__(self): >>> wxFrame.__init__(self, None, -1, "Test embedded wxFigure") >>> >>> self.fig = Figure((5,4), 75) >>> self.canvas = FigureCanvasWx(self, -1, self.fig) >>> self.toolbar = Toolbar(self.canvas) >>> self.toolbar.Realize() >>> >>> # On Windows, default frame size behaviour is incorrect >>> # you don't need this under Linux >>> tw, th = self.toolbar.GetSizeTuple() >>> fw, fh = self.canvas.GetSizeTuple() >>> self.toolbar.SetSize(wxSize(fw, th)) >>> >>> # Create a figure manager to manage things >>> self.figmgr = FigureManager(self.canvas, 1, self) >>> # Now put all into a sizer >>> sizer = wxBoxSizer(wxVERTICAL) >>> # This way of adding to sizer allows resizing >>> sizer.Add(self.canvas, 1, wxLEFT|wxTOP|wxGROW) >>> # Best to allow the toolbar to resize! >>> sizer.Add(self.toolbar, 0, wxGROW) >>> self.SetSizer(sizer) >>> self.Fit() >>> >>> def plot_data(self): >>> # Use ths line if using a toolbar >>> a = self.fig.add_subplot(111) >>> >>> # Or this one if there is no toolbar >>> #a = Subplot(self.fig, 111) >>> >>> t = numpy.arange(0.0,3.0,0.01) >>> s = numpy.sin(2*numpy.pi*t) >>> c = numpy.cos(2*numpy.pi*t) >>> a.plot(t,s) >>> a.plot(t,c) >>> self.toolbar.update() >>> >>> def GetToolBar(self): >>> # You will need to override GetToolBar if you are using an >>> # unmanaged toolbar in your frame >>> return self.toolbar >>> >>>if __name__ == '__main__': >>> app = wxPySimpleApp(0) >>> frame = PlotFigure() >>> frame.plot_data() >>> frame.Show() >>> app.MainLoop() >>>========================================================== >>> >>>how would i dissect this to create a working BOA program: >>>(ex. which one should i put on the wxApp, which should be put on the >>>wxFrame, is there anything need to be deleted in the default codes >>>generated by BOA, etc.) >>> >>>please help... thanks in advance. >>> >>> >>>------------------------------------------------------- >>>SF email is sponsored by - The IT Product Guide >>>Read honest & candid reviews on hundreds of IT Products from real users. >>>Discover which products truly live up to the hype. Start reading now. >>>http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click >> >>------------------------------------------------------- >>SF email is sponsored by - The IT Product Guide >>Read honest & candid reviews on hundreds of IT Products from real users. >>Discover which products truly live up to the hype. Start reading now. >>http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click >>_______________________________________________ >>Boa-constructor-users mailing list >>Boa...@li... >>https://lists.sourceforge.net/lists/listinfo/boa-constructor-users >> > > > > ------------------------------------------------------- > This SF.net email is sponsored by Demarc: > A global provider of Threat Management Solutions. > Download our HomeAdmin security software for free today! > http://www.demarc.com/Info/Sentarus/hamr30 |