I had trouble to find a nice plotting library in c++. I decided to try matplotlibcpp and after a while, i succeed to make it works under windows 10, visual studio 2019, Python 3.9.
First, i was trying to make it works with conda. i gave up because of trouble with setting of PYTHONHOME variable. I thus continue with a classical installation of python (3.9).
First (1), one has to be sure that python can be accessed via command prompt or powershell by typing:
python --version
Second (2), I have installed numpy and matplolib :
python -m pip install matplotlib
python -m pip install numpy
Then (3) i created a new project in cpp and I pasted those simples lines (https://github.com/lava/matplotlib-cpp) in a new cpp file:
#include <iostream>
#include "matplotlibcpp.h"
#include <vector>
namespace plt = matplotlibcpp;
int main() {
std::vector<double> y = { 1, 3, 2, 4 };
plt::plot(y);
plt::show();
}
then (4), i downloaded the matplotlibcpp.h (https://github.com/lava/matplotlib-cpp/blob/master/matplotlibcpp.h) and added it in my project

then (5), I went in the properties of the project by doing project, properties and then add in C/C++ properties, Additionnal include directories:
E:\Python39\include;E:\Python39\Lib\site-packages\numpy\core\include

then(6), in the linker, general, Additionnal library directories, i added:
E:\Python39\libs

then (7) in the linker, input, additionnal dependencies, i added:
E:\Python39\libs\python39.lib
be sure to do not delete "%(AdditionalDependencies)".

then , I compiled and get two different errors that were classical and not hard to solve:
(8) one was related to 4 lines in the matplotlibcpp.h: a comment("Sanity checks") just above those four lines, tells you that they should be comment if trouble. I did it and it works: the error doesn't appear again:

(9) the compiler also complains about something related to standard in c++. I follow guideline found on the net and just went in the properties, C/C++, langage and choose iso C++ 17 standard. Then this second error was solved.

(10) then i compiled again and i remembered that i also have complained about python39_d.lib or something like that. I just need to choose "release" and not "debug" in visual studio (and also be sure to be in X64).
(11) then, i added the python39.dll in the X64/release folder where the .exe is generated (i also added the python3.dll but i think its useless; only python39 (3x if one have different version) should be needed).

(12) then it works.
