How do I use a grid geometry manager in a matplotlib tk backend

Hi matplotlib list,

I am a resonably experienced python and matplotlib user, when it comes to make cmd line programs for batch processing, but I have never tried to make python GUI before.

I am working on a prototype product, where I want the typical matplotlib plotting window, but extended with controls, such that I can control certain parameters determining what is being plotted.

I have looked at the example

which uses the pack manager. That example works like a charm for me, and it seems like i should be able to extend it for my needs

I have also managed to add controls to that using the Tkinter module and pack(), i.e., the tedious to maintain pack manager

However, I would really like to use a grid geometry manager instead as I find it much easier to manage. I have therefore tried to modify the example to use grid instead by moifying the two pack lines in the example

#canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)


#canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)


However, when I try to run that code, I just get an empty form

I have tried other options in the grid method, with no success. I am sure i must be missing something obvious? Admittedly, these backend things are close to voodoo for me, so i am just trying to get a prrof of concepts, but i would not claim that i really undertsnad what is going on.

I have tried to look for useful documentation for doing these kinds of things, but I have had only limited success. Directions/links to relevant material would be appreciated as well.



Alan Isaac


On 3/11/2010 8:35 AM, Kim Hansen wrote:

I would really like to use a grid geometry manager instead

2010/3/11 Kim Hansen <slaunger@...287...>:


I cannot reproduce your problem. Can you maybe provide a
self-contained script to reproduce the behaviour? Here is mine:

import Tkinter
import matplotlib
tk = Tkinter.Tk()
import matplotlib.figure
fig = matplotlib.figure.Figure()
fig.set_size_inches((3, 3))
import matplotlib.backends.backend_tkagg
canvas = matplotlib.backends.backend_tkagg.FigureCanvasTkAgg(fig, master = tk)
canvas.get_tk_widget().grid(row = 0, column = 0) # or .grid(row = 0)

tk.columnconfigure(0, weight = 1)
tk.rowconfigure(0, weight = 1)
canvas.get_tk_widget().grid(row = 0, column = 0, sticky = Tkinter.NSEW)

Btw, do you know some nice way to change the xy data of a plot? At
the moment, I'm always clearing the figure and drawing again.

I also don't like the black frame around the figure, with my
self-coded backend using similar code as, I don't
observe such a black frame.