Min*_*tuz 12 shell-script gnuplot
我有 6 个文件需要绘制为带有误差范围的折线图,并将它们输出到不同的 png 文件。文件格式如下。
秒平均最小值最大值
我将如何自动绘制这些图形?所以我运行一个名为 bash.sh 的文件,它将获取 6 个文件并将图形输出到不同的.png
文件。还需要标题和轴标签。
Woj*_*tek 14
如果我理解正确,这就是你想要的:
for FILE in *; do
gnuplot <<- EOF
set xlabel "Label"
set ylabel "Label2"
set title "Graph title"
set term png
set output "${FILE}.png"
plot "${FILE}" using 1:2:3:4 with errorbars
EOF
done
Run Code Online (Sandbox Code Playgroud)
这假设您的文件都在当前目录中。以上是一个 bash 脚本,它将生成您的图表。就我个人而言,我通常gnuplot_in
使用某种形式的脚本编写一个 gnuplot 命令文件(称之为gnuplot < gnuplot_in
.
举个例子,在python中:
#!/usr/bin/env python3
import glob
commands=open("gnuplot_in", 'w')
print("""set xlabel "Label"
set ylabel "Label2"
set term png""", file=commands)
for datafile in glob.iglob("Your_file_glob_pattern"):
# Here, you can tweak the output png file name.
print('set output "{output}.png"'.format( output=datafile ), file=commands )
print('plot "{file_name}" using 1:2:3:4 with errorbars title "Graph title"'.format( file_name = datafile ), file=commands)
commands.close()
Run Code Online (Sandbox Code Playgroud)
whereYour_file_glob_pattern
是描述数据文件命名的内容,无论是它*
还是*dat
. 除了glob
模块,您os
当然也可以使用。无论生成文件名列表,真的。