0

I'm attempting to graph some data with the GNUPlot library in C++. I'm using Visual Studio 2022 with C++ 14. I also installed the boost libraries and am using the gnuplot-iostream.h file from dsthalke's GitHib repository.

As far as I understand, GNUPlot is different than MatPlotLib in the sense that it is a lower-level method of plotting data. As far as I understand, it consists of sending a series of commands via the << operator to a variable of type of Gnuplot.

I've been attempting to plot a few basic examples, from the GNUPlot documentation website and other examples.

Attempting to run Example 1 and 2 from the documentation website results in nothing happening, and the message pclose return error: No error.

Attempting to run any of the examples from this website also results in the same output.

That is, the following example code from the above website:

#include "gnuplot-iostream.h"

int main()
{
    Gnuplot plot;
    
    plot << "set dgrid3d 200,200,1";
    plot << "set pm3d";
    plot << "set palette";
    plot << "set palette color";
    plot << "set pm3d map";
    plot << "splot \"sin_cos_data\"";

    return 0;
}

Also results in nothing.

How does one graph data with GNUPlot in C++? Is there a different set of examples that I have not yet come accross, that would be better for explaining how to do it?

Thanks for reading my post, any guidance is appreciated.

Runsva
  • 365
  • 1
  • 7
  • Are you just trying to get any plot out your C++ code that uses Gnuplot library? Or are you asking how to learn Gnuplot commands? The latter is a totally different story and probably off topic here, as that would be a very broad question. – Dima Chubarov Feb 05 '23 at 11:04
  • Linked gnuplot-iostream documentation states you need at least `\n` at the end of each command: `Don't forget to put "\n" at the end of each line!`: `gp << "set xrange [-2:2]\nset yrange [-2:2]\n";` – dewaffled Feb 05 '23 at 11:35
  • Also it seems there [may be troubles](https://github.com/dstahlke/gnuplot-iostream/wiki/Portability#windows) on Windows: _When the Gnuplot object goes out of scope, the pipe is closed and gnuplot exits. This can be cured by instead using pgnuplot, but that is deprecated and seems to garble data. Perhaps better is to prompt the user to press a key before exiting your program (and before letting the Gnuplot object go out of scope)._ – dewaffled Feb 05 '23 at 11:48
  • I would first like to get any plot working with GNUPlot, whether it be an example plot or some sample data. I also tried puttin the newline character after every command, but it didn't work. – Runsva Feb 06 '23 at 00:06

1 Answers1

0

Well that's embarrassing... Turns out I didn't actually install the GNUPlot library separately.

Talk about rushing...

Runsva
  • 365
  • 1
  • 7