Skip to content

A modern C++ scientific plotting library powered by gnuplot

License

Notifications You must be signed in to change notification settings

tomcodemusic/sciplot

 
 

Repository files navigation

Overview

So, you have an amazing C++ application for which you need plotting capabilities. You have searched around and discovered that the available options for C++ plotting libraries is rather limited compared to other programming languages, such as Python, for example, which has [matplotlib].

The goal of the sciplot project is to enable you, C++ programmer, to conveniently plot beautiful graphs as easy as in other high-level programming languages. sciplot is a header-only library that needs a C++17-capable compiler, but has no external dependencies for compiling. The only external runtime dependencies are gnuplot-palettes for providing color palettes and a [gnuplot] executable.

Here is an example of sciplot in action:

#include <sciplot/sciplot.hpp>
using namespace sciplot;

int main(int argc, char** argv)
{
    // Create values for your x-axis
    Vec x = linspace(0.0, 5.0, 100);

    // Create a Plot object
    Plot plot;

    // Set color palette
    plot.palette("set2");

    // Draw a sine graph putting x on the x-axis and sin(x) on the y-axis
    plot.drawCurve(x, std::sin(x)).label("sin(x)").lineWidth(4);

    // Draw a cosine graph putting x on the x-axis and cos(x) on the y-axis
    plot.drawCurve(x, std::cos(x)).label("cos(x)").lineWidth(4);

    // Show the plot in a pop-up window
    plot.show();

    // Save the plot to a PDF file
    plot.save("plot.pdf");
}

After compiling and executing this C++ application, the following plot (plot.pdf) is produced:

Do you want to change the colors?

Simple - just use method Plot::palette to set your preferred color palette. For example, using plot.palette("parula") in the previous code sets the parula color scheme and produces the following plot:

All available color palettes and their names can be found here. Many thanks to Anna Schneider for this incredible work of art!

About

A modern C++ scientific plotting library powered by gnuplot

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 98.9%
  • Other 1.1%