Hi,

Please change plotnew to:

      def plotnew(self):
                #self.f.clf()        # clear the figure
                self.t=arange(0.0,5.0,0.05)
                self.s1=sin(2*pi*self.t)
                self.s2=self.s1*-1
                self.a.plot(self.t,self.s1,self.t,self.s2)
                self.canvas.show()

I added self.canvas.show()

This works for me.




Gregor Skrt-2 wrote:
> 
>    1.   Where can I find a good tutorial or set of examples for
>       embeding  matplotlib in Tkinter ?
>    2. Problem: I created a simple test with Tkinter. First I plot my
>       graph on __init__ (it works ok). Then I want to clear graph and
>       plot on the same canvas with different parameters. The thing is
>       that plot shows up only when I resize my window. Any idea what
>       could I be doing wrong ? I was trying draw method but it doasn't
>       work...
> 
> 
> Here is my code:
> 
> Thanks for your help. Gregor Skrt
> 
> 
> 
> 
> #!/usr/bin/env python
> 
> import matplotlib
> matplotlib.use('TkAgg')
> 
> from numpy import arange, sin, pi , cos
> from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
> NavigationToolbar2TkAgg
> from matplotlib.figure import Figure
> 
> from Tkinter import *
> import sys
> 
> class App:
>     def __init__(self,master):
>         frame = Frame(master)
>         frame.pack()
>        
>         self.button=
> Button(frame,text='Quit',fg="black",command=frame.quit)
>         self.button.pack(side=LEFT)
>        
>         self.hi_there=Button(frame,text="Plot Inverse
> sin",command=self.plotnew)
>         self.hi_there.pack(side=LEFT)
>        
>         # place a graph somewhere here
>         self.f = Figure(figsize=(5,4), dpi=100)
>         self.a = self.f.add_subplot(111)
>         self.t = arange(0.0,3.0,0.01)
>         self.s = sin(2*pi*self.t)
>         self.a.grid(True)
>         self.a.set_xlabel("cas [s]")
>         self.a.set_ylabel("amplituda")
>         self.a.plot(self.t,self.s)
>        
>         self.canvas = FigureCanvasTkAgg(self.f, master=root)
>         self.canvas.show()
>         self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
>        
>     def plotnew(self):
>         #get values from controller board, database
>         #self.f.clf()        # clear the figure
>         self.t=arange(0.0,5.0,0.05)
>         self.s1=sin(2*pi*self.t)
>         self.s2=self.s1*-1
>         self.a.plot(self.t,self.s1,self.t,self.s2)
>        
> 
> root=Tk()
> app=App(root)
> root.mainloop()   
> 
> #!/usr/bin/env python
> 
> import matplotlib
> matplotlib.use('TkAgg')
> 
> from numpy import arange, sin, pi , cos
> from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
> NavigationToolbar2TkAgg
> from matplotlib.figure import Figure
> 
> from Tkinter import *
> import sys
> 
> class App:
>       def __init__(self,master):
>               frame = Frame(master)
>               frame.pack()
>               
>               self.button= 
> Button(frame,text='Quit',fg="black",command=frame.quit)
>               self.button.pack(side=LEFT)
>               
>               self.hi_there=Button(frame,text="Plot Inverse 
> sin",command=self.plotnew)
>               self.hi_there.pack(side=LEFT)
>               
>               # place a graph somewhere here
>               self.f = Figure(figsize=(5,4), dpi=100)
>               self.a = self.f.add_subplot(111)
>               self.t = arange(0.0,3.0,0.01)
>               self.s = sin(2*pi*self.t)
>               self.a.grid(True)
>               self.a.set_xlabel("cas [s]")
>               self.a.set_ylabel("amplituda")
>               self.a.plot(self.t,self.s)
>               
>               self.canvas = FigureCanvasTkAgg(self.f, master=root)
>               self.canvas.show()
>               self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
>               
>       def plotnew(self):
>               #self.f.clf()        # clear the figure
>               self.t=arange(0.0,5.0,0.05)
>               self.s1=sin(2*pi*self.t)
>               self.s2=self.s1*-1
>               self.a.plot(self.t,self.s1,self.t,self.s2)
>               
> 
> root=Tk()
> app=App(root)
> root.mainloop()               
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco,
> CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the
> Enterprise
> -Strategies to boost innovation and cut costs with open source
> participation
> -Receive a $600 discount off the registration fee with the source code:
> SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Tkinter-problems-tp22164234p24318566.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to