Gnuplot在运行时可以接受不同的参数吗?也许和Python一起?

2024-05-02 11:06:42 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

关于Sven Marnach的解决方案中的$(在shell中,EOF之间的行被称为“here script”):在我的经验中,人们像往常一样使用shell变量,但是对于gnuplot本身的$s必须转义。

下面是一个例子:

for distrib in "uniform" "correlated" "clustered"
do
    gnuplot << EOF
    # gnuplot preamble omitted for brevity

    set output "../plots/$distrib-$eps-$points.pdf"
    set title "$distrib distribution, eps = $eps, #points = $points"

    plot "../plots/dat/$distrib-$eps-$points.dat" using 1:(\$2/$points) title "exact NN"
EOF

done

注意,反斜杠是美元的转义符,以便gnuplot看到它。

您可以将gnuplot脚本转换为shell脚本,方法是在行前加上

#!/bin/sh
gnuplot << EOF

附加行

EOF

并用\$替换每个$。然后,可以用$1替换文件名的每个出现,并用文件名作为参数调用shell脚本。

一个简单的方法是生成500个gnuplot脚本,如下所示:

for filename in list_of_files:
    outfile = open(filename + '-script', 'w')
    outfile.write(script_text % (filename,))

其中script_text是gnuplot脚本的文本,文件名替换为%s

相关问题 更多 >