Hi,

I have some problems to combine a matshow object with a canvas. Here is a little piece of code that illustrates my problem. It displays a matshow object when pressing a button.
I would like to embed the matshow object into a canvas of a fixed dimension. The code I wrote does the opposite i.e. it is the canvas that adapts its size and not the matshow object. Would you have any hints ?


******************************************************************************
from Tkinter import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import pylab

def display():
    mat = pylab.zeros((100,100))
    pylab.ioff()
    image = pylab.matshow(mat)
    pylab.ion()
    can = FigureCanvasTkAgg(image, master=frame)
    can.show()
    can.get_tk_widget().grid(row = 0,column = 0)

root = Tk()
frame = Frame(root)
frame.grid(row = 0,column = 0)
canvas = Canvas(frame, width = 240, height = 240, relief = "sunken", bg = "white")                
canvas.grid()

button = Button(root,text="DisplayMatrix",command = display)
button.grid(row = 1,column = 0)
****************************************************************************

Thank you very much

Eric


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.