Matplotlib and WPF

I have (what I thought was ) a simple question:

How do I display a matplotlib plot on WPF (running a C# application)? I want to be able to do some animation eventually, so exporting to png etc. is not an option.

I did a lot of googling but got nowhere. Any help is greatly appreciated.

···

Invite your mail contacts to join your friends list with Windows Live Spaces. It’s easy! Try it!

I'm not aware of anyone having done this.

It may require a small bit of C/C# extension code to transfer the image to the WPF window buffer (assuming you're not running IronPython and can access the necessary APIs directly from Python). You can look at the _tkagg.cpp extension for an example of how something would normally work -- but obviously it will use a completely different set of API calls for WPF. As you can see from that, though, if you use the Agg renderer matplotlib already uses and supports, the code just to get the image buffers to the screen probably won't need to be very long.

As a Windows refugee, and someone who's never used .net, I'm afraid I can't be of much more help.

Mike

V Srikanth wrote:

···

I have (what I thought was ) a simple question:

How do I display a matplotlib plot on WPF (running a C# application)? I want to be able to do some animation eventually, so exporting to png etc. is not an option.

I did a lot of googling but got nowhere. Any help is greatly appreciated.

------------------------------------------------------------------------
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! Try it! <http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us&gt;

------------------------------------------------------------------------

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Looks like I am not making much progress. I have no problems using IronPython - this is a C# application running on Vista, so it is platform dependent. I also realized that any Windows Forms control can be used in WPF, so if any one knows how to integrate matplotlib with Windows Forms, please tell me how to do it.

From what I understand matplotlib needs a graphics context to plot its graph. If I can create the gc in Windows Forms and pass it to matplotlib perhaps I can do what I want - but how do I do this using IronPython?

Solving this problem will be a great relief - the charting packages on WPF are terrible and the licensing/pricing is ridiculous (see
http://www.softwarefx.com/sfxNetProducts/ChartFX/wpf/licensing.aspx)

···

Get easy photo sharing with Windows Live™ Photos. Drag n’ drop

Again, I know little about the current state of Windows-land, but I can explain how the other backends have played out, and I assume the basics are the same.

You have basically two choices -- a) write a backend that converts all the matplotlib drawing calls to WPF gc calls or b) write a backend that uses Agg to draw, and transfers the image buffer to a window. b) will be significantly less work, and give you *identical* results which have already been heavily tuned for high quality, but it *may* be theoretically less-efficient than a). Probably not enough so to worry about.

So what you need to figure out is, given an image buffer (2D array of rgba pixels), which .net/WPF API call(s) you need to blit that to the screen, and how can you make those API calls from IronPython? Try to make a simple IronPython script that fills a Numpy array with image data, creates a window and draw the image in it (just leave matplotlib out of it for your experiments).

Given that, you could use one of the backends that takes the (b) approach (such as backend_tkagg.py) as a guide to write one for .net.

Mike

V Srikanth wrote:

···

Looks like I am not making much progress. I have no problems using IronPython - this is a C# application running on Vista, so it is platform dependent. I also realized that any Windows Forms control can be used in WPF, so if any one knows how to integrate matplotlib with Windows Forms, please tell me how to do it.

From what I understand matplotlib needs a graphics context to plot its graph. If I can create the gc in Windows Forms and pass it to matplotlib perhaps I can do what I want - but how do I do this using IronPython?

Solving this problem will be a great relief - the charting packages on WPF are terrible and the licensing/pricing is ridiculous (see
Chart FX for WPF: The next-generation in data visualization and analysis for your WPF applications.)

------------------------------------------------------------------------
Get easy photo sharing with Windows Live� Photos. Drag n� drop <http://www.microsoft.com/windows/windowslive/photos.aspx&gt;
------------------------------------------------------------------------

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA