Didier Trosset Didier Trosset - 17 days ago 7
C Question

Anyone knows a matplotlib equivalent in C or C++

I've been using matplotlib in a Python project. It is great.

I have now to plot data in a C++ project. Is anyone aware of a plotting library in C or C++?

Note that I cannot accept GPL licensed libraries.

Raj Raj
Answer

You can try something like this:

#include "Python.h"

int main()
{
   Py_Initialize();
   PyRun_SimpleString("import pylab");
   PyRun_SimpleString("pylab.plot(range(5))");
   PyRun_SimpleString("pylab.show()");
   Py_Exit(0);
   return 0;
}

compile it with(I am using a Mac):

g++ -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ plot.cpp -lpython2.6

Although you need to figure out how to make your data accessible to matplotlib (try writing it to a file and reading it back).

Hope that helps,

Raj

Comments