gnuplot的shell脚本:关于单个图中的各种输入文件,用于比较行

时间:2016-09-19 08:57:06

标签: shell gnuplot

我正在尝试使用gnuplot绘制图表并将其保存为文件。我有各种文本文件。文本文件的数量不确定。每个文本文件包含两列。文本文件是关于线性吸收光谱。第一列是频率,第二列是强度。我想通过在所有文件的单个图中绘制它们来比较光谱之间的差异。我正在使用这个脚本来做到这一点。 的

#!/bin/bash

# plot linear absorption spectrum (las)
# Usage:
# ./lasplot.sh a.ods b.ods c.ods ..

j=1
for i in $*
do
    echo "Normalization $i"
    maxle=`cat $i|tr -s "," " "|awk 'BEGIN{max=0} {if($2>max) max=$2}END{print max}'`
    echo "  The max value is $maxle"
    max[$j]=$maxle
    filename[$j]=$i
    ((j=$j + 1))
done
num=$#
echo ${filename[*]}
echo $num

read -p "Please select set data range (1) or auto set(2): " setrange
case $setrange in
1)
   read -p "set min x range: " minx
   read -p "set max x range: " maxx
   ;;
esac

# call gnuplot to plot the 1D map
gnuplot << EOF
set datafile separator ","
set title 'Linear Absorption Spectra'
set xlabel '{/Symbol w} (cm^{-1})'
set ylabel 'Intensity (a.u.)'

#set data range
if (${setrange}==1){
set xrange [$minx:$maxx]
set yrange [0:1.1]
} else {
#set xrange [0:50]
#set yrange [0:50]
}

set size 1,1
set key right top

plot "${filename[1]}" using 1:(column(2)/${max[1]}) with lines  linewidth 2 ,\
"${filename[2]}" using 1:(column(2)/${max[2]}) with points pointtype 21

pause mouse keypress "Type a letter"

set term pdfcairo font "arial,12"
set term pdfcairo enh
set term pdfcairo size 6,5
set output "las.pdf"
plot "${filename[1]}" using 1:(column(2)/${max[1]}) with lines  linewidth 2 ,\
"${filename[2]}" using 1:(column(2)/${max[2]}) with points pointtype 21

EOF

我的脚本只能绘制两个文本文件?如何更改它以绘制多个输入文件?

1 个答案:

答案 0 :(得分:0)

您可以在调用gnuplot之前在脚本中准备plot命令,将其存储到变量中,然后在gnuplot输入中重复使用它(也避免重复):

plotCmd="plot"
for((i=1;i<=${num};i++))
do
    if [ $i -eq 1 ]; then
        join=" "
    else
        join=", "
    fi
    plotCmd="${plotCmd}${join}\"${filename[$i]}\" using 1:2 with lines"
done

然后:

gnuplot << EOF

... some other stuff ...
${plotCmd}

EOF