使用gnuplot从多个文件绘制曲线 [英] Plotting curves from multiple files with gnuplot

查看:331
本文介绍了使用gnuplot从多个文件绘制曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用gnuplot在同一张图中绘制包含在不同目录中的一系列数据.

I want to plot in the same graph a series of data contained in different directories with gnuplot.

我有一个名为Ntimestep=X的文件夹集合(其中X可以是100、200、400等).在每个文件夹中,我都有一个文件occ.dat,其中包含要绘制的数据,假设3列(第一个x点,第二个和第三个y点). 我希望我的gnuplot脚本自动检测名称为Ntimestep=X的所有文件夹,并在绘图中添加文件Ntimestep=X/occ.dat中包含的数据.

I have a collection of folders called Ntimestep=X (where X can be for example 100, 200, 400 and so on). Inside each of this folder I have a file occ.dat which contains the data I want to plot, let's say 3 columns (first x points, second and third y points). I want my gnuplot script to automatically detect all the folders by the name Ntimestep=X and add the data contained in the file Ntimestep=X/occ.dat in my plot.

我还希望数字X出现在情节的图例中.

I want also the number X to appear in the legend of the plot.

示例目录结构:

- Ntimestep=100
  ~ occ.dat
  ~ <other files>
- Ntimestep=200
  ~ occ.dat
  ~ <other files>

推荐答案

Gnuplot本身无法创建此类文件列表,但是您可以调用某些命令行工具或第二个脚本来创建此类列表,然后gnuplot可以使用该脚本.

Gnuplot itself cannot create such file list, but you can call some command line tool or a second script which creates such a list, which can then be used by gnuplot.

类似

list = system('ls Ntimestep=*/occ.dat')
plot for [file in list] file

在Windows上,类似list = system('dir /b *.txt')的东西应该可以工作,请参见 Windows OS上的脚本Gnuplot (我无法对其进行测试).

On Windows something like list = system('dir /b *.txt') should work, see Script Gnuplot on windows OS (I cannot test it).

要获取标题中的数字,只需使用gnuplot即可

To get the number in the title, using only gnuplot you can use

t(s) = (s2 = s[11:*], s2[0:strlen(s2)-8])
plot for [file in list] file title t(file)

要更加灵活地使用字符串格式,您将再次需要使用外部工具(例如,将ls的输出通过sed传递).

To be more flexible regarding the string format you'll again need to use an external tool (e.g. pipe the output of ls through sed).

这篇关于使用gnuplot从多个文件绘制曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆