|
From: Allan F. <all...@ya...> - 2012-02-19 01:56:24
|
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.
--
View this message in context: http://old.nabble.com/Plot-one-additional-point%2C-manually-tp33350361p33350361.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
|
|
From: walter h. <wh...@bf...> - 2012-02-19 13:11:03
|
I think what you need is libplot from gnu plot utils, it supports things like animated gifs. see: http://www.gnu.org/software/plotutils/manual/en/html_node/Sample-C-Drawings.html#Sample-C-Drawings re, wh Am 19.02.2012 02:56, schrieb Allan Felipe: > > 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. |
|
From: Stephen W. <ste...@in...> - 2012-02-19 14:37:39
|
Allan Felipe wrote:
> 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.
>
I make animations using a fortran calling code
for each time step (while the code is ececuting).
call SYSTEM("/usr/bin/gnuplot explosion.gnu")
Each time step adds an additional point.
Hope this helps,
Stephen
--
ste...@in...
2004 route des lucioles - BP93
Sophia Antipolis
06902 CEDEX
Tel: 04 92 38 50 54
Fax: 04 97 15 53 51
|
|
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);
}
|
|
From: Allan F. <all...@ya...> - 2012-02-20 02:54:55
|
Hi, people, thanks for the answers. ( I am new here, I received 3 answers in my e-mail, shouldn't I also see them here in the forum? ) If possible I would like to keep the tool C pipe to Gnuplot. In fact, I found out a solution, but it is not elegant at all. I could save the data to a file and then read this file from inside a loop, each time adding one line. So, I plot a graphic with just 1 line, then 2 lines, then 3 lines ... I think it's not elegant because I need to save a file and then read it again, instead of using the data which is being generated. -- View this message in context: http://old.nabble.com/Plot-one-additional-point%2C-manually-tp33350361p33354569.html Sent from the Gnuplot - User mailing list archive at Nabble.com. |
|
From: Hans-Bernhard B. <HBB...@t-...> - 2012-02-20 22:49:01
|
On 20.02.2012 03:54, Allan Felipe wrote: > Hi, people, thanks for the answers. ( I am new here, I received 3 answers in > my e-mail, shouldn't I also see them here in the forum? ) This is not a forum, it's a mailing list. And IIRC it's configured to avoid sending duplicates to the direct recipient. > I think it's not elegant because I need to save a file and then read it > again, instead of using the data which is being generated. Well, like I said before: gnuplot is not designed to work the way you want to. Ultimately the data has to be stored /somewhere/. Since gnuplot doesn't store them, that means either it has to be stored in your program (and you send it all again for every re-draw), or it's stored somewhere else (e.g. in a file). |
|
From: Allan F. <all...@ya...> - 2012-02-22 23:41:51
|
> 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);
> }
Yes, that solution also works ! However I tested it and it's really slow.
Saving the data to a file and reading it is faster, like:
--------------------------------------------------------------------------------------------------------------
FILE *output;
output = fopen("data.txt", "w");
for (i = 1; i <= MAX; i++) {
x = (double) rand() / RAND_MAX;
y = (double) rand() / RAND_MAX;
fprintf(output, "%lf %lf \n", x, y);
}
fclose(output);
for (i = 1; i <= MAX; i++) {
fprintf(pipe, "plot 'data.txt' every ::1::%d using ($1*4):($2*4) pt
7 lc -1 notitle \n", i);
fflush(pipe);
usleep(1000);
}
-----------------------------------------------------------------------------------------------------------
Then, so far, I guess that's an acceptable way of using the C environment
for making animations. And if I need some extra flexibility I could save
each image and merge them with ffmpeg.
About the mailing list, I'm sending the messages through Nabble forum and I
keep receiving : Your recent message has not yet been accepted by the
mailing list and is still in the pending status. So I think it is weird that
I'm getting answers, and the mailing list actually receives my messages.
--
View this message in context: http://old.nabble.com/Plot-one-additional-point%2C-manually-tp33350361p33374456.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
|
|
From: Allan F. <all...@ya...> - 2012-02-22 23:42:24
|
> 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);
> }
Yes, that solution also works ! However I tested it and it's really slow.
Saving the data to a file and reading it is faster, like:
--------------------------------------------------------------------------------------------------------------
FILE *output;
output = fopen("data.txt", "w");
for (i = 1; i <= MAX; i++) {
x = (double) rand() / RAND_MAX;
y = (double) rand() / RAND_MAX;
fprintf(output, "%lf %lf \n", x, y);
}
fclose(output);
for (i = 1; i <= MAX; i++) {
fprintf(pipe, "plot 'data.txt' every ::1::%d using ($1*4):($2*4) pt
7 lc -1 notitle \n", i);
fflush(pipe);
usleep(1000);
}
-----------------------------------------------------------------------------------------------------------
Then, so far, I guess that's an acceptable way of using the C environment
for making animations. And if I need some extra flexibility I could save
each image and merge them with ffmpeg.
About the mailing list, I'm sending the messages through Nabble forum and I
keep receiving : Your recent message has not yet been accepted by the
mailing list and is still in the pending status. So I think it is weird that
I'm getting answers, and the mailing list actually receives my messages.
--
View this message in context: http://old.nabble.com/Plot-one-additional-point%2C-manually-tp33350361p33374457.html
Sent from the Gnuplot - User mailing list archive at Nabble.com.
|