8

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.

3
  • 1
    Must it be matplotlib? Qt has matching plotting libs too: you can take a look at QCustomPlot or Qwt. Commented Jul 11, 2014 at 6:08
  • @Tay2510 QCustomPlot and Qwt, which one is better? Thanks. Commented Jul 11, 2014 at 11:26
  • 1
    It depends. QCustomPlot is better in interactive plot but most of them are 2D plots. On the other hand, Qwt supports more complicated plots like 3D plots but less proficient at interactive plots. Commented Jul 11, 2014 at 12:59

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

I don't think it is possible to integrate with qt as this issue implies github.com/lava/matplotlib-cpp/issues/115

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.