On 6/22/07, Roman Bertle <[EMAIL PROTECTED]> wrote:

> very nice! The only remaining problem is that an analysis library
> functions might return several figures. In my case the data depends on
> several parameters, and the function returns a dictionary containing for each
> parameter set statistics, histograms and plots. The user should be able
> to decide for which parameter he wants to pop up a plot, or save it to a
> file, but for your approach all these windows pop up automatically, and
> not only when the user does a fig.show() for the figure he is interested
> in. Unfortunately the latter does not work if the figure is an
> matplotlib.figure.Figure() instance, as in my approach.

I agree with everything you say, only it is difficult to encapsulate
and get the details right for raising and hiding GUI windows across
backends, handling the mainloop etc.  Not at all impossible, but it
takes a concerted effort across 5 user interfaces.  Note I did
recently (in svn) add a fig.show() method, which will show new figures
created in an event loop after the global show starts the GUI
mainloop.

I do something similar to Ryan, but slightly more general to handle
the case you mention -- the need to possibly create multiple figures.
I define a figure generating function in my GUI code, and pass either
that function, or pylab.figure -- not pylab.figure() -- into my
functions that need to create figures.  Client code can then call that
function as often as they wish to create multiple figure windows.
I've included below a class which is callable that is used to generate
GTK figures that I sometimes use in my gtk apps.  That way functions I
use in my apps can also be called from pylab by passing in
pylab.figure

But as above, I would be very happy to have a finer degree of control
in pylab.  If you would like to take a stab at a patch to your backend
of choice to support better control of figure raising and hiding from
the pylab interface, give it a whirl.  It would make it easier for
other backend maintainers to follow your lead and port the code into
the various backends.

class GTKFigure:
    def __init__(self, title):
        self.title = title

    def __call__(self):
        from matplotlib.figure import Figure
        from matplotlib.backends.backend_gtkagg import
FigureCanvasGTKAgg as FigureCanvas
        from matplotlib.backends.backend_gtkagg import
NavigationToolbar2GTKAgg as NavigationToolbar

        win = gtk.Window()
        win.set_default_size(800,600)
        win.set_title(self.title)

        vbox = gtk.VBox()
        win.add(vbox)

        fig = Figure(figsize=(5,4), dpi=80)

        canvas = FigureCanvas(fig)  # a gtk.DrawingArea
        vbox.pack_start(canvas)
        toolbar = NavigationToolbar(canvas, win)
        vbox.pack_start(toolbar, False, False)

        win.show_all()
        return fig

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to