Setting Figure = Figure possible?

I'm new to matplotlib and python GUIs in general, so I apologize if I'm
missing something fundamental in my understanding of the matplotlib canvas -
figure - etc model. That said...

I'm working on a small matplotlib app using PyQT4. It involves selecting an
arbitrary number of data files and breaking each down into a group of 6
contour subplots. I want to be able to switch between contour plots from
each data set quickly to compare and contrast, so my thought was to
front-load the data analysis and figure creation and store them, then update
the displayed figure with a stored figure. I am not able to get the stored
figures to display though.

In attempt to debug/understand what's going on, I have the following:

class InputWindow (QtGui.QWidget):
  def __init__ (self, parent=None):
...
    self.dpi = 100
    self.fig = Figure((9.0, 6.0), dpi=self.dpi)
    self.canvas = FigureCanvas(self.fig)

    self.vbox = QtGui.QVBoxLayout()
    self.vbox.addLayout (grid)
    self.vbox.addLayout (self.hbox_pbs)
    self.vbox.addWidget (self.canvas)
    self.vbox.addStretch (1)
    self.setLayout (self.vbox)
    self.resize (900, 600)
    self.fig.add_subplot(111, aspect='equal')
...

This works fine and creates an empty plot. I can clear this figure with
self.fig.clear() and add subplots to it with self.fig.add_subplot upon
pushing a button in the UI. What I can't do is something like this:

  def Process (self):
    self.fig.clear()
    fig2 = Figure((9.0, 6.0), dpi=self.dpi)
    fig2.add_subplot(211, aspect='equal')
    self.fig = fig2
    self.canvas.draw()

This will clear the figure, but it doesn't update with the contents of fig2.
If I look at the properties of self.fig, they match those of fig2 though.
Any help on what I need to do to get something like self.fig = fig2 working?

Thanks,

J

···


View this message in context: http://www.nabble.com/Setting-Figure-%3D-Figure-possible--tp25985129p25985129.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I guess you need to update the canvas itself, but there could be more
things to do.

My recommendation is not to switch figure, but to switch axes (or just
contours).
You may create several axes in a same figure and make them invisible
(or temporarily remove them from the figure) except the one you want.

Regards,

-JJ

···

On Tue, Oct 20, 2009 at 9:15 PM, Jason Kenney <jasonkenney23@...287...> wrote:

I'm new to matplotlib and python GUIs in general, so I apologize if I'm
missing something fundamental in my understanding of the matplotlib canvas -
figure - etc model. That said...

I'm working on a small matplotlib app using PyQT4. It involves selecting an
arbitrary number of data files and breaking each down into a group of 6
contour subplots. I want to be able to switch between contour plots from
each data set quickly to compare and contrast, so my thought was to
front-load the data analysis and figure creation and store them, then update
the displayed figure with a stored figure. I am not able to get the stored
figures to display though.

In attempt to debug/understand what's going on, I have the following:

class InputWindow (QtGui.QWidget):
def __init__ (self, parent=None):
...
self.dpi = 100
self.fig = Figure((9.0, 6.0), dpi=self.dpi)
self.canvas = FigureCanvas(self.fig)

self.vbox = QtGui.QVBoxLayout()
self.vbox.addLayout (grid)
self.vbox.addLayout (self.hbox_pbs)
self.vbox.addWidget (self.canvas)
self.vbox.addStretch (1)
self.setLayout (self.vbox)
self.resize (900, 600)
self.fig.add_subplot(111, aspect='equal')
...

This works fine and creates an empty plot. I can clear this figure with
self.fig.clear() and add subplots to it with self.fig.add_subplot upon
pushing a button in the UI. What I can't do is something like this:

def Process (self):
self.fig.clear()
fig2 = Figure((9.0, 6.0), dpi=self.dpi)
fig2.add_subplot(211, aspect='equal')
self.fig = fig2
self.canvas.draw()

This will clear the figure, but it doesn't update with the contents of fig2.
If I look at the properties of self.fig, they match those of fig2 though.
Any help on what I need to do to get something like self.fig = fig2 working?

Thanks,

J

View this message in context: http://www.nabble.com/Setting-Figure-%3D-Figure-possible--tp25985129p25985129.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users