From: Werner F. B. <wer...@fr...> - 2005-04-14 09:43:53
|
Hi All, Doing multiple plots I see that memory usage grows and grows. Before doing a new plot I do "self.figure.clear()", or "self.figure.clf()", is there some other call I should use? See you Werner |
From: CASOLI J. <jul...@ce...> - 2011-01-13 13:54:13
|
Hello to all, This is yet another question about matplotlib not freeing memory, when closing a figure (using close()). Here is what I'm doing (tried with several backends, on MacOSX and Linux, with similar results): -------------------- import matplotlib as mpl from matplotlib import pylot as plt import numpy as np a = np.arange(1000000) mpl.cbook.report_memory() # -> output: 54256 plt.plot(a) mpl.cbook.report_memory() # -> output: 139968 plt.close() mpl.cbook.report_memory() # -> output: 138748 -------------------- Shouldn't plt.close() close the figure _and_ free the memory used by it? What am I doing wrong ? I tried several other ways to free the memory, such as f = figure(); ... ; del f, without luck. Any help appreciated ! P.S. : side question : how come the call to plot take so much memory (90MB for a 8MB array ?). I have read somewhere that each point is coded on three RGB floats, but it only means an approx. 12MB plot... (plus small overhead) Jules |
From: Benjamin R. <ben...@ou...> - 2011-01-13 16:00:26
|
On Thu, Jan 13, 2011 at 7:54 AM, CASOLI Jules <jul...@ce...> wrote: > Hello to all, > > This is yet another question about matplotlib not freeing memory, when > closing a figure (using close()). > Here is what I'm doing (tried with several backends, on MacOSX and Linux, > with similar results): > -------------------- > import matplotlib as mpl > from matplotlib import pylot as plt > import numpy as np > > a = np.arange(1000000) > mpl.cbook.report_memory() > # -> output: 54256 > plt.plot(a) > mpl.cbook.report_memory() > # -> output: 139968 > plt.close() > mpl.cbook.report_memory() > # -> output: 138748 > -------------------- > > Shouldn't plt.close() close the figure _and_ free the memory used by it? > What am I doing wrong ? > I tried several other ways to free the memory, such as f = figure(); ... ; > del f, without luck. > > Any help appreciated ! > > P.S. : side question : how come the call to plot take so much memory (90MB > for a 8MB array ?). I have read somewhere that each point is coded on three > RGB floats, but it only means an approx. 12MB plot... (plus small overhead) > > Jules > > > Jules, Which version of Matplotlib are you using and which backend? On my Linux install of matplotlib (development branch) using GTKAgg, the memory usage does get high during the call to show(), but returns to (near) normal amounts after I close. An interesting observation is that if the interactive mode is off, the memory usage returns back to just a few kilobytes above where it was before, but if interactive mode was turned on, the memory usage returned to being a few hundred kilobytes above where it started. Ben Root P.S. - As a side note, estimating the memory size of these plots from the given data isn't as straight-forward as multiplying by three (actually, it would be four because of the transparency value in addition to rgb). There are many other parts of the graph that needs to be represented (all having rgba values) but there are also a lot of simplifications that are done to reduce the amount of memory needed to represent these objects. |
From: gary r. <gar...@gm...> - 2011-01-14 03:05:11
|
You're not doing this from ipython are you? It's cache hangs onto the plot object references and stops python's garbage collector from releasing them. If so, you can disable the cache as a workaround. A better option would be if ipython implemented an option to avoid caching references to matplotlib objects. Gary R. On Fri, Jan 14, 2011 at 2:59 AM, Benjamin Root <ben...@ou...> wrote: > On Thu, Jan 13, 2011 at 7:54 AM, CASOLI Jules <jul...@ce...> wrote: >> >> Hello to all, >> >> This is yet another question about matplotlib not freeing memory, when >> closing a figure (using close()). >> Here is what I'm doing (tried with several backends, on MacOSX and Linux, >> with similar results): >> -------------------- >> import matplotlib as mpl >> from matplotlib import pylot as plt >> import numpy as np >> >> a = np.arange(1000000) >> mpl.cbook.report_memory() >> # -> output: 54256 >> plt.plot(a) >> mpl.cbook.report_memory() >> # -> output: 139968 >> plt.close() >> mpl.cbook.report_memory() >> # -> output: 138748 >> -------------------- >> >> Shouldn't plt.close() close the figure _and_ free the memory used by it? >> What am I doing wrong ? >> I tried several other ways to free the memory, such as f = figure(); ... ; >> del f, without luck. >> >> Any help appreciated ! >> >> P.S. : side question : how come the call to plot take so much memory (90MB >> for a 8MB array ?). I have read somewhere that each point is coded on three >> RGB floats, but it only means an approx. 12MB plot... (plus small overhead) >> >> Jules >> >> > > Jules, > > Which version of Matplotlib are you using and which backend? On my Linux > install of matplotlib (development branch) using GTKAgg, the memory usage > does get high during the call to show(), but returns to (near) normal > amounts after I close. An interesting observation is that if the > interactive mode is off, the memory usage returns back to just a few > kilobytes above where it was before, but if interactive mode was turned on, > the memory usage returned to being a few hundred kilobytes above where it > started. > > Ben Root > > P.S. - As a side note, estimating the memory size of these plots from the > given data isn't as straight-forward as multiplying by three (actually, it > would be four because of the transparency value in addition to rgb). There > are many other parts of the graph that needs to be represented (all having > rgba values) but there are also a lot of simplifications that are done to > reduce the amount of memory needed to represent these objects. > > ------------------------------------------------------------------------------ > Protect Your Site and Customers from Malware Attacks > Learn about various malware tactics and how to avoid them. Understand > malware threats, the impact they can have on your business, and how you > can protect your company and customers by using code signing. > http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > |
From: CASOLI J. <jul...@ce...> - 2011-01-14 09:23:29
|
Hooo, well done! This is it. I didn't knew about caching... I was indeed using ipython, but I did led some test using the basic python interpreter,with same results, so I did not mention this point. In fact, python's basic interpreter still records the last three outputs. As my tests were really short (plt.close() ; mpl.cbook.report_memory() ; gc.collect() is only two lines before the collect, only o)ne o,f theme outputt ing something) even pyhton's caching was still at work, and the garbage collector could not free anything. Thanks a lot, and also thanks to Ben for taking interest ! Jules PS : Gary, sorry, for the duplicated mail... Le 14 janv. 2011 à 04:04, gary ruben a écrit : > You're not doing this from ipython are you? It's cache hangs onto the > plot object references and stops python's garbage collector from > releasing them. If so, you can disable the cache as a workaround. A > better option would be if ipython implemented an option to avoid > caching references to matplotlib objects. > > Gary R. > > On Fri, Jan 14, 2011 at 2:59 AM, Benjamin Root <ben...@ou...> wrote: >> On Thu, Jan 13, 2011 at 7:54 AM, CASOLI Jules <jul...@ce...> wrote: >>> >>> Hello to all, >>> >>> This is yet another question about matplotlib not freeing memory, when >>> closing a figure (using close()). >>> Here is what I'm doing (tried with several backends, on MacOSX and Linux, >>> with similar results): >>> -------------------- >>> import matplotlib as mpl >>> from matplotlib import pylot as plt >>> import numpy as np >>> >>> a = np.arange(1000000) >>> mpl.cbook.report_memory() >>> # -> output: 54256 >>> plt.plot(a) >>> mpl.cbook.report_memory() >>> # -> output: 139968 >>> plt.close() >>> mpl.cbook.report_memory() >>> # -> output: 138748 >>> -------------------- >>> >>> Shouldn't plt.close() close the figure _and_ free the memory used by it? >>> What am I doing wrong ? >>> I tried several other ways to free the memory, such as f = figure(); ... ; >>> del f, without luck. >>> >>> Any help appreciated ! >>> >>> P.S. : side question : how come the call to plot take so much memory (90MB >>> for a 8MB array ?). I have read somewhere that each point is coded on three >>> RGB floats, but it only means an approx. 12MB plot... (plus small overhead) >>> >>> Jules >>> >>> >> >> Jules, >> >> Which version of Matplotlib are you using and which backend? On my Linux >> install of matplotlib (development branch) using GTKAgg, the memory usage >> does get high during the call to show(), but returns to (near) normal >> amounts after I close. An interesting observation is that if the >> interactive mode is off, the memory usage returns back to just a few >> kilobytes above where it was before, but if interactive mode was turned on, >> the memory usage returned to being a few hundred kilobytes above where it >> started. >> >> Ben Root >> >> P.S. - As a side note, estimating the memory size of these plots from the >> given data isn't as straight-forward as multiplying by three (actually, it >> would be four because of the transparency value in addition to rgb). There >> are many other parts of the graph that needs to be represented (all having >> rgba values) but there are also a lot of simplifications that are done to >> reduce the amount of memory needed to represent these objects. >> >> ------------------------------------------------------------------------------ >> Protect Your Site and Customers from Malware Attacks >> Learn about various malware tactics and how to avoid them. Understand >> malware threats, the impact they can have on your business, and how you >> can protect your company and customers by using code signing. >> http://p.sf.net/sfu/oracle-sfdevnl >> _______________________________________________ >> Matplotlib-users mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> |
From: gary r. <gar...@gm...> - 2011-01-15 10:37:15
|
No problem. This caught me out a long time ago and has also caught out a few people I know. On Fri, Jan 14, 2011 at 8:23 PM, CASOLI Jules <jul...@ce...> wrote: > Hooo, well done! This is it. > > I didn't knew about caching... > I was indeed using ipython, but I did led some test using the basic python interpreter,with same results, so I did not mention this point. > In fact, python's basic interpreter still records the last three outputs. As my tests were really short (plt.close() ; mpl.cbook.report_memory() ; gc.collect() is only two lines before the collect, only o)ne o,f theme outputt ing something) even pyhton's caching was still at work, and the garbage collector could not free anything. > > Thanks a lot, and also thanks to Ben for taking interest ! > > Jules > > PS : Gary, sorry, for the duplicated mail... |
From: Werner F. B. <wer...@fr...> - 2005-04-15 13:31:19
Attachments:
wxcursor_demoWClear.py
|
Hi All, I put a small test case together based on wxcursor_demo. When clicking the button1 it should show a new plot, but it does not. I think my memory issue has to do with this as I created a new self.canvas each time, instead of doing a clear, but the big question is what do I need to call to show the new plot. So, I am obviously missing something. Any hints are appreciated. See you Werner Werner F. Bruhin wrote: > Hi All, > > Doing multiple plots I see that memory usage grows and grows. > > Before doing a new plot I do "self.figure.clear()", or > "self.figure.clf()", is there some other call I should use? > > See you > Werner > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click |
From: John H. <jdh...@ac...> - 2005-04-15 13:50:50
|
>>>>> "Werner" == Werner F Bruhin <wer...@fr...> writes: Werner> Hi All, I put a small test case together based on Werner> wxcursor_demo. When clicking the button1 it should show a Werner> new plot, but it does not. It does for me... Do you mean a new plot window, or just redraw in the current figure? You may not see that it has redrawn the figure unless you somehow change the plot (ed pan/zoom). I modified your example so that each time you redraw the frequency of the sine wave changes to make it more apparent. Werner> I think my memory issue has to do with this as I created a Werner> new self.canvas each time, instead of doing a clear, but Werner> the big question is what do I need to call to show the new Werner> plot. For one thing, add a gc.collect after you call clear to trigger the garbage collector. I added a memory report function and noticed something surprising. If I just plotted the same sine wave over and over, memory usage was flat. If I changed the sine wave frequency (still creating arrays of the same size though) memory usage increased with each plot. matplotlib does cache some information, mainly text and font stuff) between draws which can cause memory to grow, but usually this is a small amount. I'll explore further. Here is my lightly modified version of your test script. The report_memory function only works on unix like systems. JDH #!/usr/bin/env python """ Show how to have wx draw a cursor over an axes that moves with the mouse and reports the data coords """ from matplotlib.numerix import arange, sin, pi import matplotlib matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx from matplotlib.figure import Figure import wx import os, sys, time, gc def report_memory(i): pid = os.getpid() a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() print i, ' ', a2[1], return int(a2[1].split()[1]) class CanvasFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1, 'CanvasFrame',size=(550,350)) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure() self.axes = self.figure.add_subplot(111) t = arange(0.0,3.0,0.01) s = sin(2*pi*t) self.axes.plot(t,s) self.axes.set_xlabel('Time (s)') self.axes.set_ylabel('Price ($)') self.canvas = FigureCanvas(self, -1, self.figure) self.canvas.mpl_connect('motion_notify_event', self.mouse_move) self.sizer =wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) buttonId = wx.NewId() self.button1 = wx.Button(id=buttonId, label='Clear and do figure again', parent=self) self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button, id=buttonId) self.sizer.Add(self.button1, 0, wx.LEFT | wx.TOP) self.SetSizer(self.sizer) self.Fit() self.statusBar =wx.StatusBar(self, -1) self.statusBar.SetFieldsCount(1) self.SetStatusBar(self.statusBar) self.add_toolbar() # comment this out for no toolbar if wx.VERSION_STRING >= '2.5': self.Bind(wx.EVT_PAINT, self.OnPaint) else: wx.EVT_PAINT(self, self.OnPaint) self.cnt = 0 def OnButton1Button(self, event): print 'done it' self.figure.clear() self.axes = self.figure.add_subplot(111) t = arange(0.0,4.0,0.01) s = sin(2*pi*t*(self.cnt+1)) #s = sin(2*pi*t) self.axes.plot(t,s) self.axes.set_xlabel('Time 2 (s)') self.axes.set_ylabel('Price 2 ($)') report_memory(self.cnt) self.cnt+=1 gc.collect() def mouse_move(self, event): self.draw_cursor(event) def add_toolbar(self): self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() self.toolbar.SetSize(wx.Size(fw, th)) self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) # update the axes menu on the toolbar self.toolbar.update() def OnPaint(self, event): self.erase_cursor() try: del self.lastInfo except AttributeError: pass self.canvas.draw() event.Skip() def draw_cursor(self, event): 'event is a MplEvent. Draw a cursor over the axes' if event.inaxes is None: self.erase_cursor() try: del self.lastInfo except AttributeError: pass return canvas = self.canvas figheight = canvas.figure.bbox.height() ax = event.inaxes left,bottom,width,height = ax.bbox.get_bounds() bottom = figheight-bottom top = bottom - height right = left + width x, y = event.x, event.y y = figheight-y dc =wx.ClientDC(canvas) dc.SetLogicalFunction(wx.XOR) wbrush =wx.Brush(wx.Colour(255,255,255), wx.TRANSPARENT) wpen =wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID) dc.SetBrush(wbrush) dc.SetPen(wpen) dc.ResetBoundingBox() dc.BeginDrawing() x, y, left, right, bottom, top = [int(val) for val in x, y, left, right, bottom, top] self.erase_cursor() line1 = (x, bottom, x, top) line2 = (left, y, right, y) self.lastInfo = line1, line2, ax, dc dc.DrawLine(*line1) # draw new dc.DrawLine(*line2) # draw new dc.EndDrawing() time, price = event.xdata, event.ydata self.statusBar.SetStatusText("Time=%f Price=%f"% (time, price), 0) def erase_cursor(self): try: lastline1, lastline2, lastax, lastdc = self.lastInfo except AttributeError: pass else: lastdc.DrawLine(*lastline1) # erase old lastdc.DrawLine(*lastline2) # erase old class App(wx.App): def OnInit(self): 'Create the main window and insert the custom frame' frame = CanvasFrame() frame.Show(True) return True app = App(0) app.MainLoop() |
From: John H. <jdh...@ac...> - 2005-04-15 14:27:32
|
>>>>> "John" == John Hunter <jdh...@ac...> writes: John> matplotlib does cache some information, mainly text and font John> stuff) between draws which can cause memory to grow, but John> usually this is a small amount. I'll explore further. I wrote a little GUI neutral script to expose the same functionality. This helps test whether the problem is backend specific or not. If you click anywhere in the axes, the sine wave updates. I see the same effect: changing the sine wave frequency causes memory usage to increase with each draw, but only for the first 50 or so draws. This appears to be an agg thing, since I see it on GTKAgg, TkAgg, WXAgg but not GTK or WX. However, I don't believe it is a memory leak. Agg may be caching some path or stroke information, because as I say the memory only seems to increase when the path is changed. However, after 50 or so draws, the increase stops, so it does not appear to be a memory leak. I often see these kinds of effects when debugging memory leaks, and typically discard the first 30-50 draws before assessing whether there is a leak or not. Here's the backend neutral script I am using, you can run it with -dWXAgg, -dWX, -dGTKAgg etc to test various backends. Note that I also explicitly clear the text cache with Text.cached = {} JDH #!/usr/bin/env python import os, sys, time, gc from matplotlib.text import Text from pylab import * def report_memory(i): pid = os.getpid() a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() print i, ' ', a2[1], return int(a2[1].split()[1]) fig = figure() ax = fig.add_subplot(111) t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) ax.plot(t,s) def click(event): fig.clear() s = sin(2*pi*t*(click.cnt+1)) ax = fig.add_subplot(111) ax.plot(t,s) gc.collect() Text.cached = {} report_memory(click.cnt) fig.canvas.draw() click.cnt += 1 click.cnt = 1 #connect('motion_notify_event', report) connect('button_press_event', click) show() |
From: Werner F. B. <wer...@fr...> - 2005-04-15 14:47:17
|
#!/usr/bin/env python """ Show how to have wx draw a cursor over an axes that moves with the mouse and reports the data coords """ from matplotlib.numerix import arange, sin, pi import matplotlib matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx from matplotlib.figure import Figure import wx class CanvasFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1, 'CanvasFrame',size=(550,350)) self.SetBackgroundColour(wx.NamedColor("WHITE")) self.figure = Figure(frameon=False) self.axes = self.figure.add_subplot(111) t = arange(0.0,3.0,0.01) s = sin(2*pi*t) self.axes.plot(t,s) self.axes.set_xlabel('Time (s)') self.axes.set_ylabel('Price ($)') self.canvas = FigureCanvas(self, -1, self.figure) self.canvas.mpl_connect('motion_notify_event', self.mouse_move) self.sizer =wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) buttonId = wx.NewId() self.button1 = wx.Button(id=buttonId, label='Clear and do figure again', parent=self) self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button, id=buttonId) self.sizer.Add(self.button1, 0, wx.LEFT | wx.TOP) self.SetSizer(self.sizer) self.Fit() self.statusBar =wx.StatusBar(self, -1) self.statusBar.SetFieldsCount(1) self.SetStatusBar(self.statusBar) self.add_toolbar() # comment this out for no toolbar if wx.VERSION_STRING >= '2.5': self.Bind(wx.EVT_PAINT, self.OnPaint) else: wx.EVT_PAINT(self, self.OnPaint) self.cnt = 0 def OnButton1Button(self, event): if self.cnt == 0: self.figure.clear() self.axes = self.figure.add_subplot(111) t = arange(0.0,4.0,0.01) s = sin(2*pi*t*(self.cnt+1)) self.axes.plot(t,s) self.axes.set_xlabel('Time 2 (s)') self.axes.set_ylabel('Price 2 ($)') if self.cnt == 2: self.figure.clear() self.axes = self.figure.add_subplot(111) t = arange(0.0,3.0,0.01) s = sin(2*pi*t*(self.cnt+1)) self.axes.plot(t,s) self.axes.set_xlabel('Time 3 (s)') self.axes.set_ylabel('Price 3 ($)') if self.cnt > 2: self.figure.clear() self.axes = self.figure.add_subplot(111) t = arange(0.0,2.0,0.01) s = sin(2*pi*t*(self.cnt+1)) self.axes.plot(t,s) self.axes.set_xlabel('Time 4 (s)') self.axes.set_ylabel('Price 4 ($)') self.cnt+=1 self.canvas.Refresh() def mouse_move(self, event): self.draw_cursor(event) def add_toolbar(self): self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() self.toolbar.SetSize(wx.Size(fw, th)) self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) # update the axes menu on the toolbar self.toolbar.update() def OnPaint(self, event): self.erase_cursor() try: del self.lastInfo except AttributeError: pass self.canvas.draw() event.Skip() def draw_cursor(self, event): 'event is a MplEvent. Draw a cursor over the axes' if event.inaxes is None: self.erase_cursor() try: del self.lastInfo except AttributeError: pass return canvas = self.canvas figheight = canvas.figure.bbox.height() ax = event.inaxes left,bottom,width,height = ax.bbox.get_bounds() bottom = figheight-bottom top = bottom - height right = left + width x, y = event.x, event.y y = figheight-y dc =wx.ClientDC(canvas) dc.SetLogicalFunction(wx.XOR) wbrush =wx.Brush(wx.Colour(255,255,255), wx.TRANSPARENT) wpen =wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID) dc.SetBrush(wbrush) dc.SetPen(wpen) dc.ResetBoundingBox() dc.BeginDrawing() x, y, left, right, bottom, top = [int(val) for val in x, y, left, right, bottom, top] self.erase_cursor() line1 = (x, bottom, x, top) line2 = (left, y, right, y) self.lastInfo = line1, line2, ax, dc dc.DrawLine(*line1) # draw new dc.DrawLine(*line2) # draw new dc.EndDrawing() time, price = event.xdata, event.ydata self.statusBar.SetStatusText("Time=%f Price=%f"% (time, price), 0) def erase_cursor(self): try: lastline1, lastline2, lastax, lastdc = self.lastInfo except AttributeError: pass else: lastdc.DrawLine(*lastline1) # erase old lastdc.DrawLine(*lastline2) # erase old class App(wx.App): def OnInit(self): 'Create the main window and insert the custom frame' frame = CanvasFrame() frame.Show(True) return True app = App(0) app.MainLoop() |
From: Matt N. <new...@ca...> - 2005-04-15 15:44:03
|
Hi Werner, I think what you may want is something like this: def OnButton1Button(self, event): print 'done it' ### self.figure.clear() ### self.axes = self.figure.add_subplot(111) self.axes.cla() # <-- clear the axes t = arange(0.0,4.0,0.01) s = sin(2*pi*t) self.axes.plot(t,s) self.axes.set_xlabel('Time 2 (s)') self.axes.set_ylabel('Price 2 ($)') self.canvas.draw() # <-- force a redraw Is that OK? It works for me on Windows and Linux. I do the same thing for 'make a fresh plot' in my own codes that I know work OK on Mac OS X as well. Cheers, --Matt |
From: Werner F. B. <wer...@fr...> - 2005-04-15 17:24:24
|
Hi Matt, Matt Newville wrote: > Hi Werner, > > I think what you may want is something like this: > > def OnButton1Button(self, event): > print 'done it' > ### self.figure.clear() > ### self.axes = self.figure.add_subplot(111) > self.axes.cla() # <-- clear the axes > t = arange(0.0,4.0,0.01) > s = sin(2*pi*t) > > self.axes.plot(t,s) > self.axes.set_xlabel('Time 2 (s)') > self.axes.set_ylabel('Price 2 ($)') > self.canvas.draw() # <-- force a redraw > > Is that OK? It works for me on Windows and Linux. I do the > same thing for 'make a fresh plot' in my own codes that I know > work OK on Mac OS X as well. Yes, that works too. So, I can do: self.figure.clear() ... self.canvas.Refresh() or: self.axes.cla() ... self.canvas.draw() or: self.figure.clear() ... self.canvas.draw() Note that all of the above still have problems if I do: self.figure = Figure(frameon=False) i.e. the "frameon=False" bit causes the figure/axes not to get totally cleared. > > Cheers, > > --Matt > > See you Werner |
From: John H. <jdh...@ac...> - 2005-04-15 18:47:52
|
>>>>> "Werner" == Werner F Bruhin <wer...@fr...> writes: Werner> Note that all of the above still have problems if I do: Werner> self.figure = Figure(frameon=False) The first thing to be drawn to the figure is the figure frame , a matplotlib.patches.Rectangle instance. This is what "clears" the background. If you want to clear the background to a certain color, set the facecolor of the figure frame to that color and it will be done. If you don't like the thin edge around the frame, set the rectangle edgecolor to be the same as the facecolor. If you want the figure to be transparent to overlay some other image, set the rectangle alpha to be 0. It will still clear the pixel buffer, but will be transparent. In other words, you should be able to get any desired effect by leaving the frame on and setting its properties. See http://matplotlib.sf.net/matplotlib.patches.html for more information on Patch/Rectangle properties. JDH |