basic question

I was asking essentially if we can deal only with matplotlib

    > objects and not (directly) with Tkinter objects. (So, e.g.,
    > we would not explicitly import Tkinter and set its mainloop,
    > and would not explicitly construct the Tk object.)

In principle, you can use the
backends.backend_tkagg.new_figure_manager to manage the figures you
create. This will handle window creation and destruction. You could
also use backends.backend_tkagg.show instead of starting the mainloop
yourself. But the usual way is to manage the GUI stuff yourself and
just use the mpl canvas and optionally, the toolbar, because when you
do GUI programming you want maximal control.

JDH

Very helpful.
Thanks,
Alan

···

On Thu, 21 Jul 2005, John Hunter apparently wrote:

In principle, you can use the
backends.backend_tkagg.new_figure_manager to manage the
figures you create. This will handle window creation and
destruction. You could also use
backends.backend_tkagg.show instead of starting the
mainloop yourself. But the usual way is to manage the GUI
stuff yourself and just use the mpl canvas and optionally,
the toolbar, because when you do GUI programming you want
maximal control.

Something came up where it pylab is a little awkward. So
I put a toe in the water of Matplotlib's more object
oriented side. This is just a user report/rumination on
some puzzles that arose when approaching Matplotlib's OO
API, for whatever it may be worth.

If you just want to save a figure to file, moving to the OO
API feels like a small but rewarding step. But if you want
GUI aspects, it feels different. Specifically, it feels
like one is immediately forced to thing substantially about
GUI aspects that might (?) have been hidden for a while
longer. I will give two examples.

1. I'm using TkAgg. I expected to find something like

def show_tkagg(figure,title=''):
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  window = Tk.Tk()
  window.wm_title(title)
  canvas = FigureCanvasTkAgg(figure, master=window)
  canvas.draw()
  canvas.get_tk_widget().pack()
  Tk.mainloop()

but with more functionality. I did not find such a thing
(which does not mean it's not there of course), and even
new_figure_manager seems less intuitive. The idea, in any
case, is that with such functions I could move more "gently"
into the GUI realm where my experience is limited (i.e.,
nil). Also the hope lingers that if I need to change
backends I can just change a 'use' and a 'show_...' and be
done.

2. This example is more speculative, since I know even less
what I'm talking about. But when I see something like
    toolbar = NavigationToolbar2TkAgg( canvas, root )
    toolbar.update()
    canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH,
    expand=1) I wonder why something like
    canvas.add_toolbar(location,...)
is not available to abstract from the GUI specific
considerations. Of course as a complete newbie in this
arena I am not really entitled to wonder such things, but
there it is.

I am not "proposing" anything here. I'm just a user
trying to be helpful by illustrating the kinds of questions that
might arise for other users as they dig a little deeper into
this amazing tool.

Cheers,
Alan Isaac

···

On Thu, 21 Jul 2005, John Hunter apparently wrote:

In principle, you can use the
backends.backend_tkagg.new_figure_manager to manage the
figures you create. This will handle window creation and
destruction. You could also use
backends.backend_tkagg.show instead of starting the
mainloop yourself. But the usual way is to manage the GUI
stuff yourself and just use the mpl canvas and optionally,
the toolbar, because when you do GUI programming you want
maximal control.