Answers:
如果我理解正确,这就是您想要的:
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
假设您的文件都在当前目录中。上面是一个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()
在哪里Your_file_glob_pattern
描述数据文件的命名,无论是*
还是*dat
。当然glob
也可以使用模块代替模块os
。实际上,无论生成什么文件名列表。
Bash解决方案,使用一个临时命令文件:
echo > gnuplot.in
for FILE in *; do
echo "set xlabel \"Label\"" >> gnuplot.in
echo "set ylabel \"Label2\"" >> gnuplot.in
echo "set term png" >> gnuplot.in
echo "set output \"${FILE}.png\" >> gnuplot.in
echo "plot \"${FILE}\" using 1:2:3:4 with errorbars title \"Graph title\"" >> gnuplot.in
done
gnuplot gnuplot.in
这可能会有所帮助。
#set terminal postfile (These commented lines would be used to )
#set output "d1_plot.ps" (generate a postscript file. )
set title "Energy vs. Time for Sample Data"
set xlabel "Time"
set ylabel "Energy"
plot "d1.dat" with lines
pause -1 "Hit any key to continue"
执行脚本文件gnuplot filename
。