the_eraser
the_eraser

Reputation: 425

Gnuplot: How to "forget" last plot and replotting only things inside an iteration

I'm plotting functions generated during an iteration. I'm using gnuplot 4.4 so the loop is done loading a file and rereading it multiple times.

plot sin(x)

i = 0
set macros
plot 0 # <==== I DON'T LIKE THIS
load "plotting_iteration"
unset macros

where "plotting_iteration" is something like:

i = i + 1
fStr = sprintf("a%d*x+b%d*sqrt(x-1)+c%d", monthN,monthN,monthN)
replot @fStr
if (i < 6) reread;

replot updates the last plot with "new plots", so I need a way to leave "sin(x)" out. The only way I found to forget about the first "plot sin(x)" is to do something like "plot 0". Is there a better way rather than my inelegant workaround? Something like "unset plot" (that does not exist).

Thanks, Luca

Upvotes: 1

Views: 312

Answers (1)

Christoph
Christoph

Reputation: 48390

You can check for i == 1 and use plot for the first plot and replot otherwise:

i = i + 1
fStr = sprintf("a%d*x+b%d*sqrt(x-1)+c%d", monthN,monthN,monthN)
if (i == 1) plot @fStr; else replot @fStr
if (i < 6) reread;

That works fine with 4.4.4

Upvotes: 1

Related Questions