Using matplotlib in Qt4/Qt4 Designer

Ewald,
If you look at the following link it may help you get started:
http://code.google.com/p/subplot/source/browse/branches/mzViewer/PyMZViewer/mpl_custom_widget.py
What you need to do is make a ui with designer and then place a widget where ever you’d like. From there make sure you right click on the widget and select horizontal layout (This is to make sure the widget occupies the GUI fully). Then right click on the widget and click on “Promote to.” From there what you need to do is select QWidget as the base class name. Using the example file I pointed to above you would put in “MPL_Widget” for the “Promoted class name” followed by “mpl_custom_widget” in the header file: field. Click promote and you should be done. Be sure to place the mpl_custom_widget.py in the directory of your converted ui file
(i.e. the one that was created using pyuic4). Now from your main window file (the one that controls adding data to the plot) you simply need to use the name of widget you promoted followed by canvas.ax etc. to manipulate the plot. For example if your promoted widget name is “plotWidget” you should be able to access the mpl API using “self.plotWidget.canvas.ax.plot(x,y,*kwargs)” where x,y, and *kwargs are the appropriate numpy arrays and keyword arguments.
I hope that helps, and let me know if you need anythinge else.
Cheers,
Brian
–ps if you need the toolbar using the latest version of matplotlib you may have to uncomment some of the code and remove some of the arguments that locate the toolbar in the ui.

···

— On Wed, 8/6/08, Ewald Zietsman <ewald.zietsman@…287…> wrote:

From: Ewald
Zietsman <ewald.zietsman@…287…>
Subject: Re: [Matplotlib-users] Using matplotlib in Qt4/Qt4 Designer
To: clowersb@…9…
Date: Wednesday, August 6, 2008, 2:47 PM

Hi,

Sorry for replying only now. Thanks for the link. I’m very new to GUI programming. Can you please explain to me how to promote a mpl widget from a regular widget? In qt3 it was possible to create a mpl widget in the form by telling the form to import your module containing the widget definition (a python class). I’m working with the qwt widgets at the moment and although they’re supposed to be fast, they don’t seem to be much faster than mpl, unless I’m doing something funny which is possible. I’m not really a programmer, but I like to tinker in order to learn as much as I can so that I can create programs to solve astrophysical problems/analyse data more efficiently (less time/less code).

Cheers

Ewald

On Wed, Aug 6, 2008 at 12:46 AM, B Clowers <clowersb@…9…> wrote:

Ewald,

It is very much a work in progress (and poorly named) but you can check out a project of mine:

http://code.google.com/p/subplot/

I created a custom matplotlib widget that you can promote from a regular widget in Designer. I hope it helps, let me know if you have any questions. The ui files are also included in the SVN. One thing to note there was a recent change to the Qt backend that altered the nature of the toolbar so you may want to comment that part out if you are using the latest matplotlib. If it is a must have I think I’m sure I could update the code when I find some time (Currently, I’m using v 0.91 I believe). Good luck.

Cheers,

Brian

— On Tue, 8/5/08, Ewald Zietsman <ewald.zietsman@…287…> wrote:

From: Ewald Zietsman <ewald.zietsman@…287…>

Subject: [Matplotlib-users] Using matplotlib in Qt4/Qt4 Designer
To: matplotlib-users@lists.sourceforge.net
Date: Tuesday, August 5, 2008, 10:06 AM

Hi All,

I’d like to use a matplotlib widget in a GUI app I’m working on. I have tried qwt but I know matplotlib a lot better and would like to use it instead. Is there anybody who have done this before? More specifically, does anyone know how to add a matplotlib widget as a custom widget in qt4 designer?

Any help will be greatly appreciated,

Ewald Zietsman


This SF.Net email is sponsored by the Moblin Your Move Developer’s

challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users