[英]Gnuplot - plot from right to left
我想用gnuplot绘制图形,想法是要有一个数据集,然后从左到右绘制表格,然后,将相同的数据乘以1.3或从右向左绘制,然后再绘制原始数据数据再次从左到右乘以0.7。
这是我从左到右的第一个图的工作代码,但是我不知道如何绘制剩余的两个图。 变量DATA是数据文件。
LINES=$(wc -l <"$DATA")
YRANGE=$(sort -n "$DATA" | sed -n '1p;$p' | paste -d: -s)
FMT=$TMPDIR/%0${#LINES}d.png
for ((i=1;i<=LINES;i++))
do
{
cat <<-PLOT
set terminal png
set output "$(printf "$FMT" $i)"
plot [0:$LINES][$YRANGE] '-' with lines t ''
PLOT
head -n $i "$DATA"
} | gnuplot
done
你能给我一些提示吗? 非常感谢你
下面的代码仅代表我建议的方法的概述; 我会留给你填补缺失的空白s
我建议创建一个函数mkplot
,该函数将被调用3次,并使用适当的乘数参数,绘图方向(1 =左至右; -1 =右至左)和输入文件名(以防万一您需要重用稍后为不同文件绘制例程)。 awk
用于进行乘法,以及以正序和逆序输出数据。 您需要在awk
部分中更改print
语句,以打印所需的gnuplot
标头。
DATA=data
function mkplot {
local factor=$1
local dir=$2
local file=$3
awk '
# multiply each data point by factor
{ a[i++]= ($0 * '$factor') }
END{
# after all lines have been processed, output result
print "set terminal png"
print "add other gnuplot options here"
print "..."
print "plot \"-\""
# dump lines in reverse order if dir=-1
if ('$dir' == -1) {for (j=i-1;j>=0;j--) print a[j] }
# or in standard order if dir=1
else { for (j=0;j < i;j++) print a[j] }
}
' $file | gnuplot # pipe the awk output to gnuplot
}
# Call the plot routine for 3 plots with different factors and directions
mkplot 1 1 $DATA
mkplot 1.3 -1 $DATA
mkplot 0.7 1 $DATA
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.