Issue with "set terminal png" Command with GNUPlot C++ (C++ 14, VS 22)

97 Views Asked by At

I'm attempting to save a GNUPlot plot as a PNG file. I'm using C++ 14 and Visual Studio 2022.

I have the following minimal example code:

#include <iostream>
#include <string>
#include <vector>
#include "gnuplot-iostream.h"

using namespace std;

int main()
{
    vector<vector<float>> data = {};

    data.push_back(vector<float>{0, 0, 0});
    data.push_back(vector<float>{1, 1, 1});
    data.push_back(vector<float>{2, 2, 2});

    Gnuplot gp;

    gp << "set terminal png\n";
    gp << "set title 'test'\n";

    gp << "set dgrid3d 100,100\n";

    gp << "splot" << gp.file1d(data) << "with pm3d title 'test'" << endl;

    gp << "set output 'test.png'\n";
    gp << "replot\n";

    return 0;
}

I noticed a really peculiar issue whenever I try to run the example code above;

Any command that is sent immediately after the set terminal png appears to get the first few of its characters removed/corrupted... In the example above, the command set title 'test' is the command sent immediately after, and this is a warning that's presented by the program console whenever I run the code above:

gnuplot> t title 'test'
         ^
         line 0: invalid command

And my plot gets generated without the title test.

I can confirm that the set terminal png is the command that causes the issue, as if I add an additional set title 'test' command, the extra command gets read properly, and my plots gets generated with the test title.

I'm aware that the GNUPlot C++ implementation is known for not being too friendly with Windows OS (which is what I'm building this on), and I was just wondering whether this was an issue encountered by someone else, or whether this is one of those Windows artifacts.

Thanks for reading my post, any suggestions are appreciated.

0

There are 0 best solutions below