1
votes

I have written a piece of code to plot a graph using GNUplot from a data file.

It's giving a warning:

warning: Skipping data file with no valid points

The code is:

{
FILE *gnuplotPipe, *tempDataFile;
FILE * pFile;
char *tempDataFileName;
char *Datafile;
double x, y;
int i;
tempDataFileName = "Pulse.txt";
Datafile = "PulseFinal.dat";
gnuplotPipe = _popen("gnuplot", "w");

if (gnuplotPipe)
{

    fprintf(gnuplotPipe, "plot \"%s\" '-' using 1:2 with lines", Datafile);
    fflush(gnuplotPipe);

    printf("press enter to continue...");
    getchar();
    fprintf(gnuplotPipe, "exit \n");
}
else
{
    printf("gnuplot not found...");
}

}

The data file is:

0.000000 0.018519
1.000000 0.000000
2.000000 0.000000
3.000000 0.000000
4.000000 0.000000
5.000000 0.000000
6.000000 0.000000
7.000000 0.000000
8.000000 0.000000
9.000000 0.000000
10.000000 -0.006173

Can someone please help me with this?

1
Send your pipe output into a file, and check if that is a valid gnuplot script. Btw.: It's "gnuplot", not "GNUplot". - Karl

1 Answers

1
votes

You have tried

plot \"%s\" '-' using 1:2 with lines

which means for Gnuplot

plot "YPulseFinal.dat" '-' using 1:2 with lines

You can't plot a file and the stream at the same time. You can

plot "YPulseFinal.dat" using 1:2 with lines

or

plot '-' using 1:2 with lines

I recommend you

fprintf(gnuplotPipe, "plot \"%s\" using 1:2 with lines", Datafile);