Gnuplot:如何在暂停后绘制文件中的每一行
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
很好的尝试,但是...
这将创建与数据文件中的行数一样多的文件。
这对我来说看起来很难看。
我们可以编写一个 shell/perl 脚本来创建 gnuplot 脚本,其中包含以下命令:
其中 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:
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.
如果你想制作动画,你最好使用专门的工具(如 mplayer)。
使用 gnuplot 准备所有源图像(第一个绘制单行,第二个绘制两行等),然后使用 mplayer 或 Convert(来自 imagemagic)从源文件生成 avi 或动画 GIF。
您可以使用以下 shell 代码片段生成输入文件的部分副本,每个副本的行数不断增加。
给定 somefile.dat ,这将生成文件“somefile-1lines.dat”、“somefile-2lines.dat”等。然后您可以使用:
按顺序绘制它们。
如果我的假设是错误的,并且您真正想要的只是这个暂停,那么您可以尝试进行设置,以便 gnuplot 将从 stdin 获取数据,然后使用此 scipt (将其命名为paused-input.sh)通过管道输入文件每行后暂停:
然后像这样调用它:
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.
Given somefile.dat this will produce files "somefile-1lines.dat", "somefile-2lines.dat", etc. Then you can use:
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:
Then invoke it like this:
要获得每次绘制一条线的效果(中间有一点停顿),使用当前版本的 gnuplot 可能更容易(自从这个问题发布以来已经过去 4 年多了)。
您可以使用
for
循环和every
关键字,如下所示:every 1::0::line_index
部分指示 gnuplot - - 在每个循环中 -- 绘制从第一行(0
)到循环当前值的数据中的每一行(1
)变量line_index
。 我们使用的是 gnuplot 帮助文本中引用的
、
和
:版本信息:
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 theevery
keyword, like this:The
every 1::0::line_index
part instructs gnuplot -- in each loop -- to draw each and every line (the1
) in the data from the first one (the0
) up to the current value of of the loop variableline_index
. What we are using is the<point_incr>
,<start_point>
and<end_point>
referred to in gnuplot's help text:Version info:
制作一个绘图文件,例如 'myplotfile.plt'。 并将您通常在 gnuplot 中键入以绘制图表的所有命令放入其中。
然后只需将该行添加
到您希望其暂停的绘图文件中,然后从终端运行它
(绘图文件的扩展名并不重要,如果您使用的是 Windows 或 Mac 盒子,您可能想使用 . txt)
绘图文件示例:
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
to your plot file where you want it to pause, and run it from the terminal with
(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: