我正在使用gnuplot进行大量绘图。由于每个图的数据范围(对于x和y轴)都是可变的,因此我需要让gnuplot自动设置范围和tic。但是,我需要在图下放置一个定义的网格,其中水平线各为1/8单位,垂直线为1/4单位。当我让gnuplot决定放置抽芯的位置时,我不知道两个抽芯之间的距离(以单位为单位),因此,我不知道我应该在m {x | y}抽芯中进行细分的数量所需的输出。
例如:如果我每两个单元都有一个ytic,则需要“设置mytics 8”。如果每个单元都有一个ytic,则需要“设置mytics 4”。
那么,是否有某种方式可以获取自动放置的tic之间的距离?甚至是绘制抽动的数量?
要获取自动放置的tic之间的距离,请使用以下代码(另存为ticstep.gp
):
xr = abs(max_value - min_value)
power = 10.0 ** floor(log10(xr))
xnorm = xr / power # approximate number of decades
posns = 20.0 / xnorm;
if (posns > 40) {
tics = 0.05
} else {
if (posns > 20) {
tics = 0.1
} else {
if (posns > 10) {
tics = 0.2
} else {
if (posns > 4) {
tics = 0.5
} else {
if (posns > 2) {
tics = 1
} else {
if (posns > 0.5) {
tics = 2
} else {
tics = ceil(xnorm)
}
}
}
}
}
}
ticstep = tics * power
这应该等效于内部gnuplot代码来确定ticstep(请参见axis.c,第677行)。
仅获取ticstep,您可以使用stats
获取相应的数据值:
stats 'file.txt' using 1 noutput
max_value = STATS_max
min_value = STATS_min
load 'ticstep.gp'
print ticstep
要获得绘制的抽线的数量,您需要自动扩展的轴限制(除非使用set autoscale fix
)。为此,您可以使用unknown
终端进行绘制以获取例如GPVAL_Y_MAX
和GPVAL_Y_MIN
:
set terminal push # save current terminal
set terminal unknown
plot 'file.txt' using 1
set terminal pop # restore terminal
max_value = GPVAL_Y_MAX
min_value = GPVAL_Y_MIN
load 'ticstep.gp'
print sprintf('ticstep = %f', ticstep)
numtics = int((xr / ticstep) + 1)
print sprintf('numtics = %d', numtics)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句