Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call python matplotlib in Qt C++ project?

Python matplotlib gives very nice figures. How to call python matplotlib in Qt C++ project? I'd like to put those figures in Qt dialogs and data are transferred via memory.

like image 335
user1899020 Avatar asked Jul 11 '14 04:07

user1899020


2 Answers

You can create a python script with function calls to matplotlib and add them as callback functions in your C++ code.

This tutorial explains how this can be done.

I also recommend reading the documentation on Python.h.

like image 86
plover Avatar answered Oct 24 '22 10:10

plover


I would try using matplotlib-cpp. It is built to resemble the plotting API used by Matlab and matplotlib. Basically it is a C++ wrapper around matplotlib and it's header only. Keep in mind though that it does not provide all the matplotlib features from python.

Here is the initial example from GitHub:

#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main() {
    plt::plot({1,3,2,4});
    plt::show();
}

Compile

g++ minimal.cpp -std=c++11 -I/usr/include/python2.7 -lpython2.7

Plot of the minimal example

like image 1
evolved Avatar answered Oct 24 '22 09:10

evolved