Skip to content

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.

Documentation

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

A conan recipe is provided

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;
}

Image of a line plot

Integration

CMake

cmake_minimum_required(VERSION 3.15)
project(PROJECT_NAME CXX)

find_package(plotpp CONFIG REQUIRED)

add_executable(main src/main.cpp)
target_link_libraries(main plotpp::plotpp)

CPM (CMake Package Manager)

TODO

Conan Package Manager

Note: not yet added to the ConanCenter

[requires]
plotpp/<version>

[generators]
CMakeDeps
CMakeToolchain

[layout]
cmake_layout
from conan import ConanFile
from conan.tools.cmake import cmake_layout


class ExampleRecipe(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeDeps", "CMakeToolchain"

    def requirements(self):
        self.requires("plotpp/<version>")

    def layout(self):
        cmake_layout(self)

build instructions with conan

# install dependencies
conan install . --build=missing --output-folder build

# generate build scripts (for the build tool e.g.: -G "Ninja Multi-Config")
cmake -S . -B build -DBUILD_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE=build/Release/generators/conan_toolchain.cmake

# build the project
cmake --build build_gcc --config Release

Conan FAQ

  • How can I make Conan use a different CMake generator?
    Add to your profile:
    [conf]
    tools.cmake.cmaketoolchain:generator=Ninja
    
  • Conan selects the wrong compiler? Add to your profile:
    [conf]
    tools.build:compiler_executables={"c" : "gcc", "cpp" : "g++"}
    
  • Where can I find the default profile?
    conan profile path default
    
  • I want to create a library but with conan create . --build=missing it cannot find the header files Enable transitive headers in your conanfile.py:
    def requirements(self):
        self.requires("<library/version>", transitive_headers=True)
    

Manually with add_subdirectory

Manually download the library and add it via add_subdirectory.

add_subdirectory(path/to/Plotpp)
add_executable(PROJECT_NAME main.cpp)
target_link_libraries(YOUR_PROJECT_NAME PUBLIC plotpp)
Note: you would also need to add and link against fmt

Manual Build

  • include the folder containing plotpp.hpp
  • compile and link all *.cpp files in plotpp/