On Thursday 08 June 2006 16:19, massimo sandal wrote: > Brian Blais ha scritto: > > I want to write a wxPython script to pull up pylab plots (in a separate > > window), based on menu or button choices. The script below crashes with > > a segmentation fault. Am I doing something wrong here? Is there a > > workaround or fix? > > As far as I know, mixing wxpython and pylab this way is BAD. > > You should better choose between: > - (1)Launch pylab in a separate thread > - (2) (What I do) Using WxMPL and embedding a matplotlib plot in a > wxPanel or wxFrame. You have to use the OO interface to matplotlib. > > m.
Hi, Agree with massimo. One brief example might help: import matplotlib matplotlib.use('WXAgg') from pylab import gca from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.font_manager import fontManager, FontProperties from matplotlib.figure import Figure from matplotlib.axes import Subplot import matplotlib.numerix as numpy from matplotlib.ticker import LogLocator, MultipleLocator from matplotlib import rcParams import wx <snip> class Your_Class(wx.Frame): def __init__(self,parent,id,title): wx.Frame.__init__(self,None,-1,"Your_Title") <snip> self.fig = Figure(figsize=(7,5),dpi=100) self.axes = self.fig.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.fig) self.parent = self.canvas.GetParent() self.canvas.mpl_connect('motion_notify_event',self.mouse_move) <snip: SomeSizer> SomeSizer.add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW|wx.EXPAND) #useful method examples: def OnRefresh(self,event=None): """ refreshes the plotting window """ self.canvas.draw() self.toolbar.update() #then the actual drawing function: def plot_data(self): """ actual plotting function """ raw_plot(self) #imported own function, see below self.toolbar.update() #not necesarry, but might help def raw_plot(parent): # note that all meta data / parameters from the parent are accessible ! # e.g. color = parent.color parent.fig.clear() a = parent.fig.add_subplot(211) etc. etc. etc. Thought this might be helpful to get started. You might want to write things a different way, though. Particularly the my application is a bit more than just a short script, so feel free to drop anything you don't want. One last thing: I'd recommend having a look at the matplotlib examples ('embedding_in_wx*.py'). Cheers, Christian _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users