Welcome to Plotpp
Plotpp
A plotting library for C++ that uses Gnuplot as a backend.
Allows plotting from custom containers/vectors if they use begin()
and end()
iterators as well as plotting from built in arrays.
Requirements
- Gnuplot: Homepage Windows Download Linux install:
Note: The project can be build without gnuplot, since this library will only communicate with gnuplot through pipes. But you will need gnuplot to display the graphical plots. - C++20
Dependencies
All dependencies are managed using CPM, a setup-free CMake dependency management system. So if you already use CMake for your C++ project, you do not have to do anything. Just include this CMake project however you like and all dependencies will be downloaded and build for you.
- CPM: Setup-free CMake dependency management
- {fmt}: formating and printing library, GitHub, Documentation
Example
#include <vector>
#include <plotpp.hpp>
#include "functions.hpp" //linspace, apply_func
int main() {
std::vector<float> x = linspace<float>(-2, 2, 100);
std::vector<double> y = apply_func(x, [](double x){return -x + x * x * x;});
using namespace plotpp;
Figure fig("Line Plot from XY");
fig.add(line(&x, std::move(y)).label("f1"));
fig.grid();
fig.show();
fig.save("line-plot.svg");
return 0;
}
Integration
CMake: CPM
Get and include the CPM script, then use CPMAddPackage()
to add git repositories as libraries to your project
include(CPM.cmake)
CPMAddPackage("gh:TobiasWallner/plotpp#main")
target_link_libraries(YOUR_PROJECT_NAME PUBLIC plotpp)
Optionally: set a download cache for your libraries by setting the environment variable CPM_SOURCE_CACHE
to a directory of your choice
CMake: Add Subdirectory
clone plotpp into your project
git clone https://github.com/TobiasWallner/plotpp.git
include the project into CMake via add_subdirectory
add_subdirectory(Path/to/plotpp)
target_link_libraries(YOUR_PROJECT_NAME PUBLIC plotpp)