closing a figure canvas?

Hello, is there a way to check if a plot is currently open? I'm using
wxAgg to show plots in a frame. I want the user to be able to show
different plots in the same frame, although only one at a time. So I
need to know if a plot is already there so I can close it and create a
new one. Thanks!

Jeff

Jeff,

Hello, is there a way to check if a plot is currently open? I'm using
wxAgg to show plots in a frame. I want the user to be able to show
different plots in the same frame, although only one at a time. So I
need to know if a plot is already there so I can close it and create a
new one. Thanks!

I think this may need to be backend dependent. For wxAgg, I put
the matplotlib figure canvas on a wx.Frame, and then check
whether that wx.Frame exists. That is, with 'self.plotframe'
being my toplevel frame that has a FigureCanvasWxAgg, and is
built with PlotFrame(), I run this prior to each plot:

    def ShowPlotFrame(self, do_raise=True):
        "make sure plot frame is enabled, and, optionally visible"
        # if plotframe does not exist, build it
        if self.plotframe == None:
            self.plotframe = PlotFrame(self)
        try:
            self.plotframe.Show()
        except wx.PyDeadObjectError:
            self.plotframe = PlotFrame(self)
            self.plotframe.Show()
  # make sure the plot frame is raised.
        if do_raise:
            self.plotframe.Raise()

The 'except wx.PyDeadObjectError:' checks if the User has killed
the Frame from the Window Manager. This could probably be made
more robust, but it works well for me.

Hope that helps,

--Matt

ยทยทยท

On Tue, 21 Jun 2005, Jeff Peery wrote: