matplotlib-cpp ============== Welcome to matplotlib-cpp, possibly the simplest C++ plotting library. It is built to resemble the plotting API used by Matlab and matplotlib. Usage ----- Complete minimal example: #include "matplotlibcpp.h" namespace plt = matplotlibcpp; int main() { plt::plot({1,2,3,4}); plt::show(); } // g++ minimal.cpp -std=c++11 -lpython2.7 Result: ![Minimal example](./examples/minimal.png) A more comprehensive example: #include "matplotlibcpp.h" #include namespace plt = matplotlibcpp; int main() { // Prepare data. int n = 5000; std::vector x(n), y(n), z(n), w(n,2); for(int i=0; i #include "matplotlibcpp.h" using namespace std; namespace plt = matplotlibcpp; int main() { // Prepare data. int n = 5000; // number of data points vector x(n),y(n); for(int i=0; i Why? ---- I initially started this library during my diploma thesis. The usual approach of writing data from the c++ algorithm to a file and afterwards parsing and plotting it in python using matplotlib proved insufficient: Keeping the algorithm and plotting code in sync requires a lot of effort when the C++ code frequently and substantially changes. Additionally, the python yaml parser was not able to cope with files that exceed a few hundred megabytes in size. Therefore, I was looking for a C++ plotting library that was extremely to use and easy to add into an existing codebase, preferrably header-only. When I found none, I decided to write one myself, which is basically a C++ wrapper around matplotlib. As you can see from the above examples, plotting data and saving it to an image file can be done is as few as two lines of code. The general approach of providing a simple C++ API for utilizing python code was later generalized and extracted into a separate, more powerful library in another project of mine, [wrappy](http://www.github.com/lava/wrappy). Todo/Issues/Wishlist -------------------- * This library is not thread safe. Protect all concurrent access with a mutex. Sadly, this is not easy to fix since it is not caused by the library itself but by the python interpreter, which is itself not thread-safe. * It would be nice to have a more object-oriented design with a Plot class which would allow multiple independent plots per program. * Right now, only a small subset of matplotlibs functionality is exposed. Stuff like xlabel()/ylabel() etc. should be easy to add. * A lot of copying could be avoided if we generate numpy arrays directly instead of python lists * If you use Anaconda on Windows, you might need to set PYTHONHOME to Anaconda home directory and QT_QPA_PLATFORM_PLUGIN_PATH to %PYTHONHOME%Library/plugins/platforms. The latter is for especially when you get the error which says 'This application failed to start because it could not find or load the Qt platform plugin "windows" in "".'