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
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯