Skip to content

A simple C++ plot library based on matplotlib and Julia's plot library (work in progress)

License

Notifications You must be signed in to change notification settings

CourrierGui/plotcpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Plotcpp

Plotcpp is a simple library which provides some tools to quickly create plots in C++. It is built on top of qcustomplot 2.0 and Qt 5.15 but can be used independently in a project once compiled.

Example

foo

#include <plotcpp/figure.hpp>

#include <vector>
#include <cmath>
#include <algorithm>

int main(int argc, char* argv[]) {
    std::vector<double> x, y;
    const double pi = std::atan(1)*4;
    const double f0 = 3;
    const double delta = 1.0/1000;

    for (double t=0; t<=1; t+=delta) {
        x.push_back(t);
        y.push_back(std::sin(2*pi*f0*t));
    }

    pcpp::Figure figure{argc, argv, 1, 1};

    figure.title("Sin function");
    figure.xlabel("x-axis");
    figure.ylabel("y-axis");
    figure.legend();
    figure.range(-0.1, 1.1, -1.1, 1.1);

    auto plot = figure.plot(x, y, "Plot");
    plot.color(127, 54, 32);
    plot.style(pcpp::Style::cross);
    figure.save("images/sin.png", pcpp::Format::png);
    return figure.show();
}

Assuming that Qt and qcustomplot are already installed, this example can be compiled with the following command: gcc -o sin sin.cpp -lplotcpp

Basics

The library is centered around 2 widgets which can be included in any Qt application:

  • PlotWidget: displays plots in a grid;
  • AnimationWidget: allows user to pass functions which will modify the underlying PlotWidget and can be controlled with signals.

Plotcpp can be used without including Qt or qcustomplot in your project using the default plot and animation windows created with the classes Figure and Animation. They provide a default interface which allows to interact with the plot and save it.

For more details about how to build plots, see the examples.

Installation

To install the library, you have to install Qt and qcustomplot. Then do the following:

git clone https://github.com/CourrierGui/plotcpp
cd plotcpp

Compilation and installation

mkdir build
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
cmake --install build --prefix /usr

On Arch based distributions:

makepkg -si

About

A simple C++ plot library based on matplotlib and Julia's plot library (work in progress)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published