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()
matplotlibtest_class.py (1.19 KB)