[Numpy-discussion] a simple examplr showing numpy and matplotlib failing

Yeates, Mathew C (388D) mathew.c.yeates at jpl.nasa.gov
Tue Dec 1 14:32:03 EST 2009


Click on "Hello World" twice and get a memory error. Comment out the ax.plot call and get no error.

import numpy

import sys
import gtk

from matplotlib.figure import Figure
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas




ax=None
fig=None
canvas=None
def doplot(widget,box1):
    global ax,fig,canvas
    data=numpy.zeros(shape=(3508,125,129))

    plot_data=data[0,0:,0]

    if canvas:
        box1.remove(canvas)
        canvas=None
    if ax:
        ax.cla()
        ax=None
    if fig: fig=None
    fig = Figure(figsize=(5,5), dpi=100)
    ax = fig.add_subplot(111)
    mif=numpy.arange(plot_data.shape[0])
    #if the next line is commented out, all is good
    ax.plot(plot_data,mif)
    canvas = FigureCanvas(fig)
    box1.pack_start(canvas, True, True, 0)
    canvas.show()

def delete_event(widget, event, data=None):
    return False

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", lambda x: gtk.main_quit())
box1 = gtk.HBox(False, 0)
window.add(box1)


button = gtk.Button("Hello World")
box1.pack_start(button, True, True, 0)
#window.add(box1)
button.show()
button.connect("clicked", doplot, box1)
box1.show()
window.set_default_size(500,400)

window.show()
gtk.main()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20091201/665f10b4/attachment.html>


More information about the NumPy-Discussion mailing list