AnyarInc / gnugraph

Header only C++ plotting interface for Gnuplot
Apache License 2.0
10 stars 0 forks source link
cplusplus cpp gnuplot header-only plot plotting

gnugraph

A header only interface to gnuplot.exe, to plot 2D and 3D graphs from C++ code.

Basic Example

int main()
{
   GnuGraph graph("C:/Program Files/gnuplot/bin/gnuplot.exe"); // provide path to executable

   vector<double> x, y;
   for (size_t i = 0; i < 200; ++i)
   {
      x.push_back(double(i));
      y.push_back(sqrt(x[i]));
   }

   const string output = graph.plot(x, y, "y = sqrt(x)");
   cout << output << '\n'; // print any errors to console
   cin.get(); // keep the window open until the user presses ENTER
   return 0;
}

Resulting graph

Features

Currently supports Gnuplot 4.6

Currently Windows only support (uses Windows piping)

3D Plotting Example

int main()
{
   GnuGraph graph;

   const size_t n = 200;
   vector<vector<double>> vec(n);
   for (size_t i = 0; i < n; ++i)
   {
      vec[i] = { cos(i / 20.0), sin(i / 30.0), cos(i / 50.0) };
   }

   graph.addLine3D(vec);
   cout << graph.plot3D() << '\n';
   cin.get();
   return 0;
}

Resulting graph