Hello,
I' m new to MPL...and rather new to Python...
so I hope I wont say too much stupidities...

I' m writing a little Fileviewer...that will plot the data of the
file...depending on some user inputs (not implemented yet)

so I started playing around...using the Tk embbeded plot exemple...
I added a "Plot" button in particular...that will plot the figure each time
it is pressed...

The program is working as expected...except memory wise...the program keeps
growing...
each time plot is pressed it's growing...I believe it's due to some poor
programming on my side, but I can't really put my finger on it right now. I
suspect that I have 2 competing mainloop maybe but i' m not really sure

If you guys could help me...
here's  the source:


from Tkinter import *
import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
FigureCanvasAgg
from matplotlib.figure import Figure

class SegDviewer():
    """class for the SegD viewer"""
    
    def __init__(self):
        """window constructor"""
        self.already_plotted = False
        self.iter = 0
        
        
        self.root = Tk()
        self.root.title("Viewer a la con")
        self.draw_button()
        self.draw_frame()
        self.root.mainloop()
        
        
    def draw_button(self):
        """places the buttons on the window"""
        Button(self.root, text = "Open"     , width = 9, command =
self.openchoose      ).pack( side = TOP )
        Button(self.root, text = "Plot"     , width = 9, command =
self.showplot       ).pack()
        Button(self.root, text = "Quit"     , width = 9, command =
self.root.quit      ).pack( side = BOTTOM)
        
    def openchoose(self):
        """open a file chooser"""
        import tkFileDialog
        
        return tkFileDialog.askopenfilename()
        
    def draw_frame(self):
        """ """
        self.myFrame = Frame(self.root, bg = 'Dark grey', height = 4*100,
width = 10*100)
        self.myFrame.pack( side = RIGHT )
        
    def showplot(self):
        """ """                
        
        try:
        #    
            self.mycanvas._tkcanvas.destroy()
        #    #self.myCanvas.delete(ALL)
        #    #self.mycanvas.destroy()
        except:
            print "there was nothing to destroy"
            
        if (True):
            #self.myCanvas = Canvas(self.myFrame, bg = 'Dark grey', height =
4*100, width = 10*100)
            self.f = Figure(figsize=(10,4), dpi=100)

          
            a = self.f.add_subplot(111)            
            t = arange(0.0,5.0,0.1)
            
            s = sin(self.iter*pi*t)
            
            a.plot(t,s)
            #a.set_title('channel')
            #a.set_xlabel('X axis label')
            #a.set_ylabel('Y label')
            self.mycanvas = FigureCanvasTkAgg(self.f, master = self.myFrame)
            self.mycanvas.draw()
            #self.mycanvas.get_tk_widget().pack(side=TOP)
            self.mycanvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)
            # a tk.DrawingArea
            
            
            #self.myCanvas.pack()
            #self.mycanvas.draw()
            
            self.iter = self.iter + 1
 
        

application = SegDviewer()   



 
-- 
View this message in context: 
http://www.nabble.com/Correct-usage-of-Mpl-backend...-tp21012938p21012938.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to