gnuplot:紧凑轴标签格式

gnuplot: compact axis label format

告诉我如何在 gnuplot 中正确形成轴上的铭文(如图所示)。

1) 我不知道y轴的值

2) 我需要在轴标签中自动设置指数(10 次方)

在绘图之前,您需要知道数量级。您可以通过 stats 获取此信息。然后将您的 y 值除以一个因子(在下面的示例中),该因子被选择为使得轴 tics 应显示 0 到 100 之间的值。

代码:

### automatic prefactor in axis scaling and axis label
reset session

# generate some random data
set samples 20
RandomMagnitude = floor(rand(0)*20-10)
RandomValue = rand(0)
set table $Data
    plot '+' u 0:(RandomValue*10**RandomMagnitude/([=10=])) with table
unset table

# get the maximum via stats
stats $Data u 2 nooutput
Max = STATS_max

PrefactorLog = ceil(log10(Max))-2
Prefactor = 10**PrefactorLog

set ylabel sprintf("Y-title, x 10^{%d} units",PrefactorLog)
set format y "%g"
set boxwidth 0.7 relative

plot $Data u 1:(/Prefactor) with boxes fs solid 1.0 fc rgb "red" ti sprintf("Max value %.2e", Max)
### end of code

结果: