Im trying to plot a graph from a C program, i have a file plot_data.txt that contains the following data:
x y 0.000 0.000002 1.000 0.000003 2.000 0.000004 3.000 0.000006 4.000 0.000007 5.000 0.000008 6.000 0.000009 7.000 0.000010 8.000 0.000011 0.000 0.000000
Its only two columns, X and Y, im trying to use the following command to plot but i cant get a result
include <stdio.h> include <stdlib.h> define GNUPLOT "gnuplot -persist"</stdlib.h></stdio.h>
int main(int argc, char *argv) { FILE gp; gp = popen(GNUPLOT, "w"); fprintf(gp, "plot 'plot_data.txt' with linespoints linestyle 1"); fclose(gp); }
The line fprintf(gp, "plot 'plot_data.txt' with linespoints linestyle 1"); dosnt open de Gnuplot. What command should i use to work?
fprintf(gp, "plot 'plot_data.txt' with linespoints linestyle 1");
I suspect you need to put a \n at the end of that string. Without it, you haven't sent a command line, so nothing for the gnuplot core to process.
\n
Log in to post a comment.
Im trying to plot a graph from a C program, i have a file plot_data.txt that contains the following data:
x y
0.000 0.000002
1.000 0.000003
2.000 0.000004
3.000 0.000006
4.000 0.000007
5.000 0.000008
6.000 0.000009
7.000 0.000010
8.000 0.000011
0.000 0.000000
Its only two columns, X and Y, im trying to use the following command to plot but i cant get a result
include <stdio.h>
include <stdlib.h>
define GNUPLOT "gnuplot -persist"</stdlib.h></stdio.h>
int main(int argc, char *argv)
{
FILE gp;
gp = popen(GNUPLOT, "w");
fprintf(gp, "plot 'plot_data.txt' with linespoints linestyle 1");
fclose(gp);
}
The line fprintf(gp, "plot 'plot_data.txt' with linespoints linestyle 1"); dosnt open de Gnuplot. What command should i use to work?
Last edit: Mario Judah 2020-12-13
I suspect you need to put a
\n
at the end of that string. Without it, you haven't sent a command line, so nothing for the gnuplot core to process.