File Gnuplot:如何在暂停后绘制文件中的每一行

File Gnuplot:如何在暂停后绘制文件中的每一行,file,gnuplot,File,Gnuplot,我有一个3列数据文件,我想使用splot来绘制相同的数据文件。 但我想要的是gnuplot绘制第一行(以某种颜色,比如红色),然后暂停0.3秒,然后继续绘制下一行(以其他颜色,而不是红色,比如绿色),暂停0.3秒,然后继续绘制下一行……以此类推 任何帮助都将不胜感激 提前谢谢 关于Pankaj如果您想制作动画,最好使用专门的工具(如mplayer) 使用gnuplot准备所有源图像(第一个是单行打印的,第二个是两行打印的,等等),然后使用mplayer或convert(来自imagemagic)

我有一个3列数据文件,我想使用splot来绘制相同的数据文件。 但我想要的是gnuplot绘制第一行(以某种颜色,比如红色),然后暂停0.3秒,然后继续绘制下一行(以其他颜色,而不是红色,比如绿色),暂停0.3秒,然后继续绘制下一行……以此类推

任何帮助都将不胜感激

提前谢谢


关于Pankaj

如果您想制作动画,最好使用专门的工具(如mplayer)

使用gnuplot准备所有源图像(第一个是单行打印的,第二个是两行打印的,等等),然后使用mplayer或convert(来自imagemagic)从源文件生成avi或动画GIF

您可以使用以下shell代码段生成输入文件的部分副本,每个副本的行数都在增加

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
给定somefile.dat,这将生成文件“somefile-1lines.dat”、“somefile-2lines.dat”等。然后您可以使用:

for f in *lines.dat ; do
  gnuplot ... $f 
done
按顺序绘制它们

如果我的假设是错误的,而您真正想要的只是这个暂停,那么您可以尝试进行设置,以便gnuplot将从stdin获取数据,然后使用这个scipt(名称为paused input.sh)在每一行之后使用暂停的管道输入文件:

#!/bin/bash
while read l ; do
  echo "$l"
  sleep 1
done
然后像这样调用它:

(pause-input.sh | gnuplot ...) < somefile.dat
# 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
}
(pause-input.sh | gnuplot…)
很好的尝试,但是。。。 这将创建与数据文件中的行数相同的文件。 我觉得这很难看

我们可以编写一个shell/perl脚本来创建gnuplot脚本,其中包含如下命令:

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

其中席号中的Xi、Yi、Zi=坐标数据文件。 暂停1将暂停一秒钟


这只是一个想法,但我不知道如何直接绘制坐标,而不是向gnuplot提供数据文件。

制作一个绘图文件,例如“myplotfile.plt”。并将通常在gnuplot中键入的用于绘制图形的所有命令放入其中

然后再加上一行

!sleep $Number_of_Seconds_to_Pause
到要暂停打印文件的位置,并使用从终端运行打印文件

gnuplot myplotfile.plt
(绘图文件的扩展名无关紧要,如果您使用的是windows或mac设备,则可能需要使用.txt)

绘图文件示例:

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

在当前版本的gnuplot中,一次画一条线(中间有一点停顿)可能更容易获得效果(这个问题发布已经有4年多了)

您可以为
-循环使用
,并使用
每个
关键字,如下所示:

(pause-input.sh | gnuplot ...) < somefile.dat
# 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
}
every1::0::line_index
部分指示gnuplot——在每个循环中——绘制数据中从第一行(
0
)到循环变量
line_index
的当前值的每一行(
1
)。我们使用的是gnuplot帮助文本中提到的

 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>}}}}}
 [...]