csv - Gnuplot 统计数据无法按预期工作 : max value not right

标签 csv statistics command gnuplot

假设有以下4个数据集:

a.csv

1,1
2,3
3,5
5,6
6,9
7,9
8,10
9,12
10,13

b.csv

1,1
2,5
3,10
5,15
6,20
7,25
8,30
9,35
10,40

c.csv

1,1
2,10
3,100
5,1000
6,2000
7,5000
8,10000
9,20000
10,50000

d.csv

1,1
2,20
3,300
5,5000
6,9000
7,10000
8,15000
9,30000
10,100000

在 Gnuplot 中,我尝试对它们中的每一个运行命令 stats 以获得 xy 的最大值(即, 12 列)并设置相应的 xrangeyrange。不幸的是,结果不是我所期望的。

这是完整的脚本:

#!/usr/bin/env gnuplot
set terminal latex
set term pngcairo enhanced size 1500,800
set output 'plot.png'
set multiplot layout 2,2
set xlabel 't' font ',16'
set ylabel '#pkt' font ',16'
set grid xtics lt 0 lw 1 lc rgb "#333333"
set grid ytics lt 0 lw 1 lc rgb "#333333"
set xtics font ',14'
set ytics font ',14'
set key font ',12'
set title font ',20'
set datafile separator ','
###
set title '(a)'
stats "a.csv" using 1:2 name "a"
set xrange [0:a_max_x]
set yrange [0:a_max_y+a_max_y*0.5]
plot "a.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
###
set title '(b)'
stats "b.csv" using 1:2 name "b"
set xrange [0:b_max_x]
set yrange [0:b_max_y+b_max_y*0.5]
plot "b.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
###
set title '(c)'
stats "c.csv" using 1:2 name "c"
set xrange [0:c_max_x]
set yrange [0:c_max_y+c_max_y*0.5]
plot "c.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
###
set title '(d)'
stats "d.csv" using 1:2 name "d"
set xrange [0:d_max_x]
set yrange [0:d_max_y+d_max_y*0.5]
plot "d.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
###
unset multiplot

结果:

enter image description here

如您所见,bcd 图中的最大值不正确。实际上,stats 的详细输出返回:

[...]
Maximum:      10.0000 [8]       13.0000 [8]
[...]
Maximum:      5.0000 [3]       15.0000 [3]
[...]
Maximum:      2.0000 [1]       10.0000 [1]
[...]
Maximum:      1.0000 [0]        1.0000 [0]
[...]

显然,只有情节的统计数据 a 是正确的。我的脚本有什么问题吗?

最佳答案

每次设置完 xrangeyrange 后,你需要重新初始化它们,否则 stats 会发现你们中的一些点超出了你的范围以前设置,不考虑它们。这是下面的最后一行:

set title '(a)'
stats "a.csv" using 1:2 name "a"
set xrange [0:a_max_x]
set yrange [0:a_max_y+a_max_y*0.5]
plot "a.csv" using 1:2 title 'v1' with lines linewidth 3 linecolor rgb 'blue'
set xrange [*:*] ; set yrange [*:*] # <--- This line after each plot will fix your issue

关于csv - Gnuplot 统计数据无法按预期工作 : max value not right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23075679/

相关文章:

java - 从命令行运行 Java 程序

c++ - 二维数据点集的加权线性最小二乘法

c - 从 C 在 Paraview 上打印值

powershell - 在Powershell中从CSV删除标题

java - Excel无法理解java写入的数据格式

matlab - cdf 的倒数

r - 有没有办法通过从 R 中的模型中获取参数来构造真实的回归方程?

objective-c - 如何在一致的环境中循环使用 NSTask 运行终端命令?

当前工作目录的 Unix 定位命令

Python - 理解 CSV 模块和 line_num 对象