|
From: Thomas S. <t.s...@fz...> - 2012-02-19 17:25:37
|
Allan Felipe <allanfelipebr <at> yahoo.com.br> writes:
>
>
> Hi, I would like to plot a set of points which is being generated by a C
> code, using pipe. It would plot a sequence of these points making a video.
> Here is an example that does the job:
>
> ----------------------------------------------------------------
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> int main() {
>
> FILE *pipe;
> pipe = popen("gnuplot -persist", "w");
>
> fprintf(pipe, "set xlabel 'x (m)' \n");
> fprintf(pipe, "set ylabel 'y (m)' \n");
> fprintf(pipe, "set pointsize 1 \n");
> fprintf(pipe, "set xrange[-0.1:4.1] \n");
> fprintf(pipe, "set yrange[-0.1:4.1] \n");
>
> int i;
> double x, y;
>
> for (i = 1; i < 30; i++) {
> x = (double) rand() / RAND_MAX;
> y = (double) rand() / RAND_MAX;
>
> fprintf(pipe, "plot '< echo %lf, %lf' w p pt 7 lc -1 notitle \n",
> 4*x, 4*y);
>
> fflush(pipe);
> usleep(150000);
> }
>
> fclose(pipe);
> return 0;
> }
>
>
--------------------------------------------------------------------------------
>
> It works ... however, the way it is done, it plots just one point at a time.
> I would like to plot one point, then another one, but keeping the last point
> ... then another, keeping all the other 2 ... so I'd like to know how I
> could add one point to a graph that is already done, that would solve my
> problem.
maybe the 'replot' command helps:
for (i = 0; i< 30; i++) {
x = (double) rand() / RAND_MAX;
y = (double) rand() / RAND_MAX;
if (i) {
fprintf(pipe,
"replot '< echo %lf, %lf' w p pt 7 lc -1 notitle \n",
4*x, 4*y);
} else {
fprintf(pipe,
"plot '< echo %lf, %lf' w p pt 7 lc -1 notitle \n",
4*x, 4*y);
}
fflush(pipe);
usleep(150000);
}
|