5

i have a 3 column datafile and i wanted to use splot to plot the same. But what i want is that gnuplot plots first row (in some colour, say red) and then pauses for say 0.3 secs and then moves on to plotting next row (in other colour, not in red, say in green), pauses for 0.3 secs and then proceeds to next row....so on n so forth.

Any help will be greately appreciated.

thanks in advance

Regards Pankaj

4 Answers 4

3

Good attempt but... This will create as many files as the number of lines in data file. This looks ugly to me.

We can write a shell/perl script to create gnuplot script with commands in it like:

splot x1 y1 z1
pause 1
replot x2 y2 z2
pause 1
replot x3 y3 z3
pause 1
replot x4 y4 z4

where xi, yi, zi = coordinates in data file for ith line number. pause 1 will pause it for one sec.

This is just an idea, though am not sure how to plot coordinates directly instead of supplying a data file to gnuplot.

Sign up to request clarification or add additional context in comments.

Comments

2

If you want to produce an animation, you better use specialized tools for it (like mplayer).

Use gnuplot to prepare all source images (first one with single row plotted, second - with two lines, etc), then use mplayer or convert (from imagemagic) to produce avi or animated GIF out of source files.

You can use the following shell snippet to produce partial copies of the input file, each with increasing number of lines.

file="your input file.dat"
lines=$(wc -l $file)
i=1
while [ $i -le $lines ] ; do
  head -${i} ${file} > ${file%.dat}-${i}lines.dat
done

Given somefile.dat this will produce files "somefile-1lines.dat", "somefile-2lines.dat", etc. Then you can use:

for f in *lines.dat ; do
  gnuplot ... $f 
done

to plot them all in sequence.

If my assumption is wrong and all you really want is this pause, then you can try to set things up so that gnuplot will get data from stdin, and then use this scipt (name it paused-input.sh) to pipe input file with pauses after each line:

#!/bin/bash
while read l ; do
  echo "$l"
  sleep 1
done

Then invoke it like this:

(pause-input.sh | gnuplot ...) < somefile.dat

Comments

2

To get the effect of drawing each line one at a time (with a little pause in between) is perhaps easier with the current version of gnuplot (it's been over 4 years since this question was posted).

You can use a for-loop, and the every keyword, like this:

# Find out the number of lines in the data somehow, 
# for example like this:
num_lines="`cat my_datafile.d | wc -l`"

# Plot the first line in the data-file:
plot './my_datafile.d' every 1::0::0

# For the remaining lines:
do for [line_index = 1:num_lines-1] { 
  pause 0.3
  # Replot (from the same datafile) each line 
  # in the data file from the first one up to 
  # the current line_index 
  replot '' every 1::0::line_index
}

The every 1::0::line_index part instructs gnuplot -- in each loop -- to draw each and every line (the 1) in the data from the first one (the 0) up to the current value of of the loop variable line_index. What we are using is the <point_incr>, <start_point> and <end_point> referred to in gnuplot's help text:

 gnuplot> help every
 The `every` keyword allows a periodic sampling of a data set to be plotted.
 [...]

 Syntax:
    plot 'file' every {<point_incr>}
                       {:{<block_incr>}
                         {:{<start_point>}
                           {:{<start_block>}
                             {:{<end_point>}
                               {:<end_block>}}}}}
 [...]

Version info:

$ gnuplot --version
gnuplot 4.6 patchlevel 0

Comments

0

make a plotfile eg. 'myplotfile.plt'. and put in it all the commands you would normally type in gnuplot to plot your graphs.

then just add the line

!sleep $Number_of_Seconds_to_Pause

to your plot file where you want it to pause, and run it from the terminal with

gnuplot myplotfile.plt

(the extension of the plotfile doesn't matter, if you're on a windows or mac box you might like to use .txt)

example of plotfile:

set title 'x squared'
plot x**2 title ''
!sleep 5
set title 'x cubed'
plot x**3 title ''
!sleep 5

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.