Code Monkey home page Code Monkey logo

! WARNING ! sciplot has been redesigned and there were breaking API changes between v0.2 and v0.3. See the tutorials and the API documentation for the new version.

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
    Plot2D plot1;
    // Set color palette for first Plot
    plot1.palette("paired");
    // Draw a sine graph putting x on the x-axis and sin(x) on the y-axis
    plot1.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
    plot1.drawCurve(x, std::cos(x)).label("cos(x)").lineWidth(2);

    // Create a second Plot object
    Plot2D plot2;
    // Draw a tangent graph putting x on the x-axis and tan(x) on the y-axis
    plot2.drawCurve(x, std::tan(x)).label("tan(x)").lineWidth(4);

    // Put both plots in a "figure" horizontally next to each other
    Figure figure = {{plot1, plot2}};

    // Create a canvas / drawing area to hold figure and plots
    Canvas canvas = {{figure}};
    // Set color palette for all Plots that do not have a palette set (plot2) / the default palette
    canvas.defaultPalette("set1");

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

    // Save the plot to a SVG file
    canvas.save("example-readme.svg");
}

After compiling and executing this C++ application, the following plot (example-readme.svg) 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!

sciplot's Projects

gnuplot-palettes icon gnuplot-palettes

Modified gnuplot color palettes from github.com/Gnuplotting/gnuplot-palettes adapted for sciplot project

sciplot icon sciplot

A modern C++ scientific plotting library powered by gnuplot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.