0

I have two data set (x,y1) and (x,y2) which I got from the result of computation and wrote those files in "data1.tmp" & "data2.tmp". I want to use this two data set to plot in Gnuplot.

#include <iostream>
#include <cstdlib>

int main()
{
    FILE* gnupipe1, *gnupipe2;
    
    const char* GnuCommands1[] = {"set title \"v vs x\"","plot \'data1.tmp\' with lines"};
    const char* GnuCommands2[] = {"set title \"y vs x\"","plot \'data2.tmp\' with lines"};

    gnupipe1 = _popen("gnuplot -persistent","w");
    gnupipe2 = _popen("gnuplot -persistent", "w");

    for (int i = 0; i < 2; i++)
    {
        fprintf(gnupipe1,"%s\n",GnuCommands1[i]);
        fprintf(gnupipe2,"%s\n", GnuCommands2[i]);
    }
    return 0;
}

Now when I run the program two window shows up plotting the data accurately.

How to plot multiple data set this way? say (x,y1) & (x,y2) in same window?

1
  • One solution (doesn't know if it is the best, but it works): Use one File * only, and for the second curve (data2.tmp), use replot instead of plot. Commented Mar 11, 2022 at 15:16

1 Answer 1

0

You are opening two different gnuplots, you don't need to do that.

#include <iostream>
#include <cstdlib>

int main()
{
    FILE* gnupipe1;
    
    const char* GnuCommands1[] = {"set title \"v vs x\"",
                 "plot \'data1.tmp\' with lines, \'data2.tmp\' with lines"};

    gnupipe1 = _popen("gnuplot -persistent","w");

    for (int i = 0; i < 2; i++)
        fprintf(gnupipe1,"%s\n",GnuCommands1[i]);

    return 0;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.