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

Joe Kington jkington@wisc....
Wed Dec 2 14:41:12 CST 2009


I'm just guessing here, but have you tried completely destroying the figure
each time, as Michael suggested?

That should avoid the problem you're having, I think...

At any rate, if you don't do a fig.clf(), I'm fairly sure matplotlib keeps a
reference to the data around.

Hope that helps,
-Joe

On Wed, Dec 2, 2009 at 11:55 AM, Yeates, Mathew C (388D) <
mathew.c.yeates@jpl.nasa.gov> wrote:

>  Anybody have any ideas what is going on here. Although I found a
> workaround, I’m concerned about memory leaks
>
>
>  ------------------------------
>
> *From:* numpy-discussion-bounces@scipy.org [mailto:
> numpy-discussion-bounces@scipy.org] *On Behalf Of *Yeates, Mathew C (388D)
> *Sent:* Tuesday, December 01, 2009 6:53 PM
>
> *To:* Discussion of Numerical Python
> *Subject:* Re: [Numpy-discussion] a simple examplr showing numpy and
> matplotlib failing
>
>
>
> I found  a workaround. If I replace
>
> > plot_data=data[0,0:,0]
>
> With
>
> > plot_data=numpy.copy(data[0,0:,0])
>
>
>
> Everything is okay.
>
>
>
> I am on Windows XP 64 with 4 Gigs ram. (Note: the data array is greater
> than 4 Gigs since my datatype is float64. If I decrease the size so that the
> array is around 3 Gigs, all is good)
>
>
>
>
>
> Mathew
>
>
>
>
>
>
>
>
>  ------------------------------
>
> *From:* numpy-discussion-bounces@scipy.org [mailto:
> numpy-discussion-bounces@scipy.org] *On Behalf Of *Santanu Chatterjee
> *Sent:* Tuesday, December 01, 2009 12:15 PM
> *To:* Discussion of Numerical Python
> *Subject:* Re: [Numpy-discussion] a simple examplr showing numpy and
> matplotlib failing
>
>
>
> Hi Mathew,
>     I saw your email and I was curious about it. I tried your code and it
> does work for me without any problem.
>
> Santanu
>
> On Tue, Dec 1, 2009 at 2:58 PM, Michael Droettboom <mdroe@stsci.edu>
> wrote:
>
> Hmm... works for me. What platform, with how much physical and virtual RAM?
>
> One thing you may want to try is to completely destroy the figure each
> time:
>
> if fig:
> fig.clf()
> fig=None
>
> Mike
>
>
> Yeates, Mathew C (388D) wrote:
> >
> > 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()
> >
>
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >
>
> --
> Michael Droettboom
> Science Software Branch
> Operations and Engineering Division
> Space Telescope Science Institute
> Operated by AURA for NASA
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091202/0102d058/attachment.html 


More information about the NumPy-Discussion mailing list