Thanks John. I know I have some clean up to do, I just want to do it right so it isn't an annual (or more often) thing....
On 3/15/07, John Hunter <[EMAIL PROTECTED]> wrote: > On 3/15/07, Ryan Krauss <[EMAIL PROTECTED]> wrote: > > > How should I be using matplotlib/pylab in my utility scripts so that > > they are compatible with embedding in wx? > > A good rule of thumb is to never import pylab at the top level for > modules that need to be imported. In my own code, I often do > something like > > def somefunc(figfunc): > fig = figfunc() > ax = fig.add_subplot(111) > ax.plot([1,2,3]) > > and then I can call it with > > somefunc(pylab.figure) > > or a custom func that generates a GUI embedded figure instance. Eg, > in my GTKApps, I have a functor like gtk_figure that returns a > function that creates a figure embedded in a GTK window. > > In basemap, Jeffrey Whitaker does something like the following > > def somefunc(ax=None): > if ax is None: > import pylab > ax = pylab.gca() > > Here the pylab import is triggered only when the function is called > with default arguments. That way you can use it from GUI code without > triggering a pylab import like > > somefunc(ax) > > and from other code where you want pylab do do everything with > > somefunc() > > I'm afraid you have some cleanup to do..... Mixing pylab with > embedded GUI code is a recipe for pain and misery. > > JDH > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users