给出一个用gnuplot生成的非常简单的图表:
$Data << EOD
2021-09-30 83360000000.0000
2021-12-31 123945000000.0000
2022-03-31 97278000000.0000
2022-06-30 82959000000.0000
2022-09-30 90146000000.0000
2022-12-31 117154000000.0000
2023-03-31 94836000000.0000
2023-06-30 81797000000.0000
2023-09-30 89498000000.0000
EOD
set xdata time
set timefmt "%Y-%m-%d"
set format y "%.0s %c"
plot $Data using 1:2 with boxes
有没有办法格式化 y 轴以使用更多
k
表示数千,m
表示数百万,b
表示数十亿,t
表示数万亿,而不是科学记数法的字符替换(即 k
,) M
、G
等)?
这里建议在轴上一次仅使用一个前缀。具有 multiplt 前缀的对数刻度也可能是可能的,但我想自动缩放会变得很困难,并且您必须“半手动”放置 tic 标签。
您需要确定您的范围的数量级。您必须小心,因为 gnuplot 似乎在格式化和确定正确的幂方面存在问题。 例如:
print int(log10(1000)/3) # should return 1, but returns 0
print gprintf("%T",95) # should return 1, but returns 2
第一个结果肯定是舍入误差(二进制/十进制表示),但第二个结果我认为是
gprintf()
函数中的错误。无论如何,我猜下面的函数(通过绕行字符串)将返回正确的幂(至少,到目前为止我还没有看到错误的结果):
power(n) = int(sprintf("%e",abs(n))[strstrt(sprintf("%e",abs(n)),'e')+1:])
那么,脚本的作用是:
stats
获取最大绝对值来确定前缀所以,将此视为一个起点......
脚本:
### use different prefixes k,m,b,t
reset session
$Data1 << EOD
2021-09-30 83360000000.0000
2021-12-31 123945000000.0000
2022-03-31 97278000000.0000
EOD
$Data2 <<EOD
2021-09-30 8336000.0000
2021-12-31 12394500.0000
2022-03-31 9727800.0000
EOD
$Data3 <<EOD
2021-09-30 833.60
2021-12-31 1239.45
2022-03-31 972.78
EOD
power(n) = int(sprintf("%e",abs(n))[strstrt(sprintf("%e",abs(n)),'e')+1:])
prefix(n) = word('"" k m b t', power(n)/3+1)
set format x "%Y\n%b" timedate
set yrange [0:]
set style fill solid 0.4
set boxwidth 0.8 relative
set key noautotitle
set multiplot layout 3,1
stats $Data1 u (abs($2)) nooutput
pow3 = int(power(STATS_max)/3)*3
set format y "%.1f ".prefix(STATS_max)
plot $Data1 using (timecolumn(1,"%Y-%m-%d")):($2/10**pow3) with boxes
stats $Data2 u (abs($2)) nooutput
pow3 = int(power(STATS_max)/3)*3
set format y "%.1f ".prefix(STATS_max)
plot $Data2 using (timecolumn(1,"%Y-%m-%d")):($2/10**pow3) with boxes
stats $Data3 u (abs($2)) nooutput
pow3 = int(power(STATS_max)/3)*3
set format y "%.1f ".prefix(STATS_max)
plot $Data3 using (timecolumn(1,"%Y-%m-%d")):($2/10**pow3) with boxes
unset multiplot
### end of script
结果: