pylab crashes simple wxPython script

Hello Brian,

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?

A couple of things, as a first sight:

from wxPython.wx import *

This style is no more suggested (and I think it's time for it to become deprecated). Use:

import wx

Instead.

import pylab

You should actually use the OO interface of pylab, meaning matplotlib:

import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure

<snip>

def New(self, event):
  
  myframe = wx.Frame(self, None, -1, "Test embedded wxFigure")

  fig = Figure((9,8), 75)
  canvas = FigureCanvasWx(myframe, -1, fig)

  axis = fig.add_subplot(111)
      
  t = numpy.arange(0.0,3.0,0.01)
      s = numpy.sin(2*numpy.pi*t)
      c = numpy.cos(2*numpy.pi*t)
      axis.plot(t,s)
      axis.plot(t,c)

Something along these lines should work. Please double-check what I have written. You may also want to look at the matplotlib example "embedded_in_wx.py" in the matplotlib web page.

HTH.

Andrea.

···

_________________________________________
Andrea Gavana (gavana@kpo.kz)
Reservoir Engineer
KPDL
4, Millbank
SW1P 3JA London

Direct Tel: +44 (0) 20 717 08936
Mobile Tel: +44 (0) 77 487 70534
Fax: +44 (0) 20 717 08900
Web: http://xoomer.virgilio.it/infinity77
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

I have pylab working fine in XP and in Linux with wxPython 2.6.1.0
(newer wxPython + VTK is broken, I haven't had time to look at this,
hence no upgrading for me yet). The trick was the following:

    # interactive mode: user can use pylab commands from any introspection
    # interface, changes will be made immediately and matplotlib cooperates
    # nicely with main WX event loop
    matplotlib.interactive(True)

Let me know if this helps.

···

On 6/8/06, Brian Blais <bblais@bryant.edu> wrote:

thanks for the quick reply. I am aware of the embedding possibilities, but this is
*not* what I want to do. first, I want to use the pylab syntax (which is simpler).
second, I want the scripts to be able to be run without the interface. I just want
my wx controls to pop up a separate pylab window.