Calling matplotlib from C++ ?

Hi,

Each time I'm working on C++ codes using vector or valarray, I would
like to be able to plot them.
The problem is that there is no straitforward way to do that in C++.
My goal is not to code a QT or GTK application but only to be able to
plot 1D and 2D things from one given large C++ code without having to
add lots of lines of codes in my code (let say it is intend to be used
in debug phase).

Questions :
Is there a way to call pylab plot and imshow from a C++ code ?
In this case, I do not care if we have to copy the array and it can be slow.
It would be a so nice feature to debug C++ image processing codes.
Any example of code is welcome even they are not calling matplotlib but
anthing else in python.

Xavier.
ps : In my codes, 2D images are stored as in a class derived from
valarray (1D array) adding the size of the image along the 2 directions
as private members.

···

--
############################################
Xavier Gnata
CRAL - Observatoire de Lyon
9, avenue Charles André
69561 Saint Genis Laval cedex
Phone: +33 4 78 86 85 28
Fax: +33 4 78 86 83 86
E-mail: gnata@...419...
############################################

Hi Xavier,

you should really check out the Boost::Python libraries. They allow you, among
other things, to expose your C++ container classes as python objects. I'm
using them heavily in my project and I'm very satisfied. Check them out here:

http://www.boost.org/libs/python/doc/

HTH,

  Francesco

···

On Saturday 16 December 2006 19:42, Xavier Gnata wrote:

Hi,

Each time I'm working on C++ codes using vector or valarray, I would
like to be able to plot them.
The problem is that there is no straitforward way to do that in C++.
My goal is not to code a QT or GTK application but only to be able to
plot 1D and 2D things from one given large C++ code without having to
add lots of lines of codes in my code (let say it is intend to be used
in debug phase).

Questions :
Is there a way to call pylab plot and imshow from a C++ code ?
In this case, I do not care if we have to copy the array and it can be
slow. It would be a so nice feature to debug C++ image processing codes.
Any example of code is welcome even they are not calling matplotlib but
anthing else in python.

Xavier.
ps : In my codes, 2D images are stored as in a class derived from
valarray (1D array) adding the size of the image along the 2 directions
as private members.

yardbird wrote:

Each time I'm working on C++ codes using vector or valarray, I would
like to be able to plot them.

you should really check out the Boost::Python libraries. They allow you, among other things, to expose your C++ container classes as python objects. I'm using them heavily in my project and I'm very satisfied.

What this means is that you'd be using python to drive your C++ code, rather than using C++ code to drive a python/mpl code. In addition to Boost::Python, there are some other options to consider:

pyrex, Cxx, SWIG.

The other option is to use your C++ code to drive Python. This can be done by embedding a python interpreter in your C++ app. See the odfficial pyhton docs, and lots of other stuff online.

You also might want to check out Elmer:

http://elmer.sourceforge.net/

I've never used it, but it looks pretty cool. It's a tool that provides the infrastructure for calling python from C/C++.

Honestly, though, I'd go with the first approach -- drive your C++ code from Python -- I think that in addition to making it easy to plot results, etc, you'll be able to write unit tests, etc in python, and even get a full scripting engine, which could turn out to be very useful..

-Chris

···

On Saturday 16 December 2006 19:42, Xavier Gnata wrote:

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Christopher Barker wrote:

yardbird wrote:
  

Each time I'm working on C++ codes using vector or valarray, I would
like to be able to plot them.
      
you should really check out the Boost::Python libraries. They allow you, among
other things, to expose your C++ container classes as python objects. I'm
using them heavily in my project and I'm very satisfied.
    
What this means is that you'd be using python to drive your C++ code,
rather than using C++ code to drive a python/mpl code. In addition to
Boost::Python, there are some other options to consider:

pyrex, Cxx, SWIG.

The other option is to use your C++ code to drive Python. This can be
done by embedding a python interpreter in your C++ app. See the
odfficial pyhton docs, and lots of other stuff online.

You also might want to check out Elmer:

http://elmer.sourceforge.net/

I've never used it, but it looks pretty cool. It's a tool that provides
the infrastructure for calling python from C/C++.

Honestly, though, I'd go with the first approach -- drive your C++ code
from Python -- I think that in addition to making it easy to plot
results, etc, you'll be able to write unit tests, etc in python, and
even get a full scripting engine, which could turn out to be very useful..

-Chris
  

Hi,

I do agree that driving C++ from python looks easier thant driving
python from C++.
However, I really would like to inclue python code into my C++ code and
not the opposite (I have special needs so I really have to do that).

I'm going to have a look at embedding python.
Has anyone experience with that?

Xavier

···

On Saturday 16 December 2006 19:42, Xavier Gnata wrote:

--
############################################
Xavier Gnata
CRAL - Observatoire de Lyon
9, avenue Charles André
69561 Saint Genis Laval cedex
Phone: +33 4 78 86 85 28
Fax: +33 4 78 86 83 86
E-mail: gnata@...419...
############################################