【问题标题】:Gnuplot - plot from right to leftGnuplot - 从右到左绘图
【发布时间】:2016-04-06 12:14:50
【问题描述】:

我想用 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

你能给我一些提示吗?非常感谢

【问题讨论】:

    标签: bash plot gnuplot


    【解决方案1】:

    下面的代码仅代表我建议的方法的概要;我会留给你来填补缺失的空白?

    我建议创建一个函数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
    

    【讨论】:

      猜你喜欢
      • 2020-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2022-01-18
      相关资源
      最近更新 更多