2
votes

How can I open two (or more) Gnuplot windows from a C program, using a single pipe? The code below only seems to create the graph for data created by the second loop. The window for data created by the first loop either isn't created or doesn't stay open. I am using AquaTerm to display Gnuplot graphs and don't want to have to open multiple instances of this. I also like using '-' so that I don't have to create text files to be read by Gnuplot.

int main()
{
    FILE *gnuplotPipe = popen("/usr/local/bin/gnuplot -persistent", "w");
    fprintf(gnuplotPipe, "plot '-' with lines\n");
    for (int i = 0; i < 11; i++) {
        fprintf(gnuplotPipe, "%d\t%d\n", i, i);
    }
    fprintf(gnuplotPipe, "e\n");

    fprintf(gnuplotPipe, "plot '-' with lines\n");
    for (int i = 10; i < 21; i++) {
        fprintf(gnuplotPipe, "%d\t%d\n", i, i);
    }
    fprintf(gnuplotPipe, "e\n");

    return 0;
}

I have tried using -persist in the plot commands, but haven't managed to get this to work.

Just to be clear, I want to be able to compare graphs in different windows, not in the same window.

1

1 Answers

7
votes

You can use different windows using different windows numbers:

set terminal aqua
plot x
set terminal aqua 1
plot x**2

The default number is 0.

This should work with all interactive terminals (wxt, x11, aqua, qt, windows).