wxList and FigureCanvasWx

RE: [Matplotlib-users] wxList and FigureCanvasWx
Hello –

I’m having a dickens of a time getting this to work…

I believe I understand what you mean about maintaining a list of FigureCanvasAggs and using string & bitmap methods to get the figures into my wxDialog.

Where I’m stuck is in plotting a histogram to a FigureCanvasAgg… I’ve checked out your examples, but there doesn’t appear to be anything that directly uses FigureCanvasAgg. I’ve tried many different ways (mostly based on the embedded_in_wx.py and histogram_demo.py examples).

Based on the example “histogram_demo.py” could you please give some pointers as to how to plot the histogram to a FigureCanvasAgg? I think I can handle things after that…

Thanks for your assistance!

Dave Engelsma

Lacks Wheel Trim Systems


-----Original Message-----

From: John Hunter [mailto:jdhunter@…4…]

Sent: Saturday, April 24, 2004 9:53 AM

To: Engelsma, Dave

Cc: matplotlib-users@lists.sourceforge.net

Subject: Re: [Matplotlib-users] wxList and FigureCanvasWx

> Hello - I''ve got a wxDialog where, among other
> controls, I have a wxList and a
> FigureCanvasWx. Depending on what single item is
> selected in the wxList, the FigureCanvasWx should show
> the appropriate graph. It's important that the
> matplotlib-generated graph stay in the dialog along
> with the other controls (I don't want to generate a
> separate frame for the graph).

I’m not a wx guru, so this may not be the best way, but it I think it

is a pretty good way. Instead of putting a FigureCanvasWX in your,

use a wxPanel instead. Maintain a list of FigureCanvasAgg and use

them to draw your figures. Transfer these to the wxPanel using string

and bitmap methods. This is effectively what wxagg does. The main

difference is that you will have one canvas and a list of


You can get the width and height of the figure you need to draw with

Suppose agg below is an FigureCanvasAgg instance

    s = agg.tostring_rgb()
    l,b,w,h = agg.figure.get_window_extent().get_bounds()
    image = wxEmptyImage( w,h )
    bitmap = image.ConvertToBitmap()

You can then transfer the bitmap to the wxpanel. If you want to do

all the ‘draw’ calls upfront so you don’t have to repeatedly draw if

the user selects one figure, then another, then the original, that

will be fine.

Agg is a pretty fast renderer, which may more than make up for the

performance hit of having to go through the string->bitmap->canvas.

Let me know how it goes.