Plot real-time results from a running C++ algorithm without saving data to a file first
Add line charts and scatter plots to a C++ numerical simulation with two lines of code
Visualize C++ algorithm output during development without switching to Python or MATLAB
Create 3D surface plots from C++ scientific computing data
Requires Python 3 and matplotlib installed on the same machine, you must link your C++ compiler against the Python runtime, which adds CMake configuration steps.
matplotlib-cpp is a C++ library that lets you draw charts and graphs from inside a C++ program. It works by calling Python's matplotlib library behind the scenes, so it requires Python to be installed on the same machine alongside a few Python packages. The library itself is just one file you drop into your project, with no complicated build system required. To use it, you include the single header file in your C++ code and write chart commands that look very similar to how you would draw charts in Python or MATLAB. A simple line chart can be created in two lines of code. The library supports many chart types: line plots, scatter plots, 3D surface plots, arrow plots, and even an xkcd hand-drawn style. Setting it up takes a bit more work than a typical C++ library because of the Python dependency. On Ubuntu or a similar Linux system you install a few Python packages, then link your C++ compiler against the Python runtime. CMake build files are included to help with this. The library works with both Python 2 and Python 3, though Python 3 is the default in the build configuration. One limitation to be aware of: because it starts a Python interpreter internally, you cannot use any other library in the same program that also starts its own Python interpreter. Only one Python session can run per process. The project was created during a graduate thesis when the author needed to view charts while a C++ algorithm was still running, rather than saving data to a file first and plotting it separately afterward. That origin explains the focus on simplicity: the goal was the smallest possible gap between having numbers in C++ and seeing a chart on screen.
← lava on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.