gnuplot:紧凑轴标签格式

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

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

1)我不知道y轴的值

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

enter image description here

format label gnuplot axis exponential
1个回答
3
投票

在绘图之前,您需要知道数量级。你可以通过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/($0)) 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:($2/Prefactor) with boxes fs solid 1.0 fc rgb "red" ti sprintf("Max value %.2e", Max)
### end of code

结果:

enter image description here

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