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

发布于 2024-07-07 11:34:39 字数 197 浏览 9 评论 0原文

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

任何帮助将不胜感激。

提前致谢

问候 Pankaj

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

垂暮老矣 2024-07-14 11:34:39

很好的尝试,但是...
这将创建与数据文件中的行数一样多的文件。
这对我来说看起来很难看。

我们可以编写一个 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 = 数据文件中第 i 行号的坐标。
暂停 1 将暂停一秒钟。

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

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.

音盲 2024-07-14 11:34:39

如果你想制作动画,你最好使用专门的工具(如 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

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
提笔落墨 2024-07-14 11:34:39

要获得每次绘制一条线的效果(中间有一点停顿),使用当前版本的 gnuplot 可能更容易(自从这个问题发布以来已经过去 4 年多了)。

您可以使用 for 循环和 every 关键字,如下所示:

# 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
}

every 1::0::line_index 部分指示 gnuplot - - 在每个循环中 -- 绘制从第一行(0)到循环当前值的数据中的每一行(1)变量line_index。 我们使用的是 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>}}}}}
 [...]

版本信息:

$ gnuplot --version
gnuplot 4.6 patchlevel 0

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
是伱的 2024-07-14 11:34:39

制作一个绘图文件,例如 '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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文