Windows操作系统上的脚本Gnuplot

时间:2014-10-14 09:13:27

标签: windows bash automation gnuplot

我想从数据文件列表中自动生成图形。

更多细节: 我有一个包含所有数据文件的目录。我需要为每个文件生成一个图表(数百个)。我有一个gnuplot文件来生成一个图,但是数据文件的名称被指定到gnuplot脚本中。

例如:

plot 'myfile' index 1  using 1:2 with linespoints pointtype 2 linecolor rgb "green"  title "leg"

我需要能够替换" myfile"通过可以在我的目录的所有文件上迭代的变量名称。

2 个答案:

答案 0 :(得分:2)

您可以使用以下命令创建(Windows)批处理文件:

for %%G in (*.dat) do gnuplot.exe -e "fn='%%G'" script

这将为当前目录中的每个.dat文件运行gnuplot(和 script )。

-e开关用于input variables via command line(此处为文件名,如果包含空格,则用引号括起来。)

如果要直接从shell运行此命令(而不是批处理文件中),请从两对中删除其中一个%符号。

在脚本文件中:

plot fn index 1  using 1:2 with linespoints pointtype 2 linecolor rgb "green"  title "leg"

如果数据文件具有"标准化"姓名(例如data1.datdata2.dat ...)查看https://stackoverflow.com/a/14947085/3235496

答案 1 :(得分:2)

通常,您可以按如下方式迭代gnuplot中的许多文件:

set terminal pdfcairo
list = "fileA fileB fileC"

do for [file in list] {
    set output file . '.pdf'
    plot file
}

这种迭代至少需要4.6.0版本。在此示例中,您有一个固定的文件名列表(不允许包含空格)。

在Windows上,您可以使用

list = system('dir /b *.txt')

获取包含当前目录中所有.txt个文件的列表。请注意,您必须使用wgnuplot_pipes.exe才能生效。

在Unix系统上你可以使用

list = system('ls *.txt')
相关问题