如何按最后 y 值的顺序对键进行排序?

问题描述 投票:0回答:1

我已经在 gnuplot 中管理了一个图表。现在我想优化键中的顺序。我的解决方案是在 gnuplot 之外以预处理数据的形式进行。但也许你们中有人知道 gnuplot 中有一个简单的解决方案?

key 中条目的位置应按最后 y 值排序。这将导致曲线的每个入口都没有交叉线。

通过 gnuplot 测量温度:

数据的形式为:

2023-10-28 14:17:01     59.125  34.875  43.500  25.375  26.125  45.312  44.687  26.125  57.750
2023-10-28 14:18:01     59.125  34.937  43.875  25.375  26.125  45.437  44.750  26.187  57.750
2023-10-28 14:19:01     59.250  35.000  43.937  25.375  26.125  45.437  44.812  26.187  57.875
2023-10-28 14:20:01     59.187  35.062  43.562  25.375  26.125  45.562  44.812  26.250  57.750
2023-10-28 14:21:01     59.125  35.125  43.625  25.375  26.125  45.562  44.875  26.312  57.812

我的 gnuplot 脚本中有趣的部分

stats 'temp.txt' using (last1=$1,last2=$2,last3=$3,last4=$4,last5=$5,last6=$6,last7=$7,last8=$8,last9=$9,last10=$10) nooutput
set size 0.8,1
set arrow from graph 1,first last4  to screen 0.8, first 70 nohead
set key outside Left reverse

plot \
  "temp.txt"         using  1:4 with lines title sprintf("Vorlauf Solar, %0.1f°"  , last4 ) at screen 0.84, first 70,   \
  "temp.txt"         using  1:3 with lines title sprintf("Warmwasser, %0.1f°"     , last3 ) at screen 0.84, first 65,   \
gnuplot visualization
1个回答
0
投票

虽然这基本上是重新排序gnuplot关键条目的重复,但我投票赞成重新打开这个问题,以便给出gnuplot>=5.4.0的答案,这比那里的答案更简单。此外,该问题的用户似乎不再活跃了。

评论:

  • 执行
    stats
    获取行数和列数
  • 将订单号(=列号-1)和最后一个 y 值绘制到数据块中
    $Temp
    ,同时将所有列标题合并到字符串中
    headers
  • 使用
  • $Temp
    $Order
     绘制到数据块 
    smooth zsort
     中(需要 gnuplot>=5.4.0)。这可能是(到目前为止)使用 
    gnuplot-only 对值进行排序的最简单方法。这些行将包含第 1 列中的最后 y 值(降序排列)和相应的订单号(第 2 列中)。
  • 按相应顺序绘制数据和关键条目

数据:SO77379457.dat


X Data1 Data2 Data3 Data4 Data5 Data6 Data7 Data8 0 96.4 93.3 99.5 97.3 95.9 91.9 98.9 98.0 1 96.1 93.2 99.5 97.6 96.0 91.9 98.7 98.4 2 96.0 93.1 99.3 97.7 95.7 91.5 99.2 98.2 3 96.5 92.8 99.2 97.8 96.1 92.0 99.2 98.3 4 96.7 92.3 99.0 97.4 95.7 91.8 99.0 97.9 5 96.3 92.3 99.4 97.5 95.7 92.3 98.7 98.2 6 95.9 92.7 99.4 97.4 96.0 91.9 99.1 98.7 7 95.8 92.4 99.2 97.0 96.4 91.6 99.5 98.5

脚本:(需要 gnuplot>=5.4.0)

### re-order key in order of last y-value reset session FILE = "SO77379457.dat" stats FILE u 0 nooutput rowMax = STATS_records-1 colMax = STATS_columns headers = '' set table $Temp plot for [col=2:colMax] FILE every rowMax u ($0==0?headers=headers.' '.columnheader(col):col-1):col w table set table $Order plot $Temp u 2:1:(-$2) smooth zsort unset table set key noautotitle out Left reverse plot for [col=2:*] FILE u 1:col w lp pt 7 lw 2 lc col-1, \ for [i=0:rowMax-1] $Order every ::i::i u (NaN):(NaN):(t=int($2)) w lp pt 7 lc var ti word(headers,t) ### end of script

结果:

© www.soinside.com 2019 - 2024. All rights reserved.