On Fri, Aug 23, 2013 at 9:55 AM, Kari Aliranta <
kari.p.alira...@student.jyu.fi> wrote:

> Hello, fellow Matplotlib users,
>
>
> I'm embedding some Matplotlib figures into GUI (PyQt4) windows or widget
> canvases using qt4agg as the backend. I'm having problems with these
> figures popping up any time when some other part of the program calls
> pyplot.show().
>
> How do you avoid this showing of previous figures? Is there some hidden
> buffer where the figures go? If there is, what is the way to clear this
> buffer, or preferably avoid putting figures in this buffer altogether?
> I'd be happy to handle these figures as simple individual objects.
>
> (I'm aware that this "hidden buffer" may be the pylab/pyplot buffer. I
> tried deepcopying the figure and then clearing the pylab buffer with
> pylab.clf() , but figures don't seem to be deepcopyable.)
>
>
> A  typical situation is the following:
>
> - There is a window with a widget. The widget (widgetMpl in the code
> below) has a slightly customized FigureCanvas in it. The drawing code is
> activated by clicking a button in the window. The code goes as follows.
>
>      # The plot method returns a complicated instance of Figure with
> several axes, constructed with Pylab.
>      previewFigure =
> self.parent.experiment.file_to_plot.plot(show=False, n_channels=10)
>
>      self.ui.widgetMpl.canvas.figure = previewFigure
>      self.ui.widgetMpl.canvas.draw()
>
>
> - I draw the figure in the window once, or several times with different
> file_to_plot, by pressing the button. I may or may not close the window
> with the aforementioned widget.
>
> - Elsewhere in the program there is another window with very simple
> drawing code using pyplot. When this code calls pyplot.show(), all the
> figures drawn in the first window will show up.
>
>
>
It is called the "pyplot state environment".  When code uses pylab or
pyplot, the pyplot state implicitly keeps track of all the axes and figures
that are generated. The way to avoid the pyplot state environment is to
completely avoid any and all usage of pyplot. Don't even import it. Work
strictly down in the OO layer. Of course, this is difficult to do for a
variety of reasons, but it should be achievable.  There are other people on
this mailing list that are much more experienced than I with the pure
OO-approach and embedding, and hopefully they can chime in with pointers
and tips.

Cheers!
Ben Root
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to