Matplotlib animation in wxPython, sizing / redrawing quirk

Hi, folks,

I will be posting this question to both matplotlib-users and wxpython-
users. Apologies to those of you who have to endure my ramblings two
times in a row!

Using this example by John Bender,

http://www.scipy.org/Matplotlib_figure_in_a_wx_panel

I recently constructed a working, animated matplotlib graph in a
wxPython frame. A sample output is here:

http://www.flickr.com/photos/15579975@N00/6145518550

In that example, the text block is in wxPython, and the color bar for
the graph's Z scale is a bitmap object which is again handled by wx.
Only the live graph is rendered by matplotlib.

Once I accomplished this, I attempted a more complicated, multiple-
subplot display, this time with the text boxes handled by matplotlib
rather than wx. I also tried removing parts of Mr. Bender's code that
I thought that I would not need. Specifically, I've disabled resizing
of my matplotlib panel. But when I removed the code associated with
sizing, I discovered that my animation disappeared. The first frame
would draw, then nothing.

Digging deeper, I learned that redrawing is SOMEHOW accomplished in
the PlotPanel._SetSize method. _SetSize is called repeatedly, when
there's a wx.IDLE message. In _SetSize, you have to call
PlotPanel.SetSize (note, no underscore this time) and
FigureCanvasWxAgg.SetSize on EVERY cycle to make animation work. The
matplotlib figure.set_size method needs only to be called the first
time -- at least, in my case, where I've disabled resizing. I haven't
tested a resizable window.

Here are my questions.

1) I do not recall seeing this kind of behavior in wxPython before.
Why does wxPython treat matplotlib objects differently?

2) How exactly is sizing making the redrawing happen? Is this a good
method to use? The indirect nature of this redrawing-by-sizing
approach sent me on a long and pointless hunt for bugs in my own
code. Finally, how can I determine how MUCH redrawing is taking place
on my matplotlib canvas? I am trying to implement eight image plots
simultaneously, with some overlaid contours, and some live text,
too. But sometimes I only have to update four of the eight plots, or
just the text. Does matplotlib know which parts of its image are
"dirty" and confine its updates appropriately?

Many thanks for your insights!

Bump, with a point of emphasis:

···

On Oct 3, 2:11 pm, John Ladasky <lada...@my-deja.com> wrote:

How exactly is sizing making the redrawing happen? Is this a good
method to use? The indirect nature of this redrawing-by-sizing
approach sent me on a long and pointless hunt for bugs in my own
code.

In other words, fellow Pythoneers, "explicit is better than
implicit." Wouldn't you say?

I'm still wondering that I was supposed to know that a resize method
was actually also the redraw method, even when no resizing actually
occurs.

Yeah, it's probably a bad idea. But since I'm not familiar with the code in question I can't comment on it much more than that. There are some design patterns that would include some drawing in the EVT_SIZE handler, for example to create a new buffer the new size of the window and then redrawing the existing content to that buffer, but that would not typically be the only place that the drawing is done.

···

On 10/4/11 5:03 PM, John Ladasky wrote:

Bump, with a point of emphasis:

On Oct 3, 2:11 pm, John Ladasky<lada...@my-deja.com> wrote:

How exactly is sizing making the redrawing happen? Is this a good
method to use? The indirect nature of this redrawing-by-sizing
approach sent me on a long and pointless hunt for bugs in my own
code.

In other words, fellow Pythoneers, "explicit is better than
implicit." Wouldn't you say?

I'm still wondering that I was supposed to know that a resize method
was actually also the redraw method, even when no resizing actually
occurs.

--
Robin Dunn
Software Craftsman