gpt4 book ai didi

gnuplot - 如何获取自动生成的 gnuplot tic 之间的距离?

转载 作者:行者123 更新时间:2023-12-02 16:14:53 42 4
gpt4 key购买 nike

我正在使用 gnuplot 绘制大量绘图。由于每个图的数据范围(x 轴和 y 轴)都是可变的,因此我需要让 gnuplot 自动设置范围和控制。但是,我需要在绘图下方放置一个定义的网格,水平线各 1/8 个单位,垂直线各 1/4 个单位。当我让 gnuplot 决定在哪里放置抽动时,我不知道两个抽动之间的距离(以单位为单位),因此,我不知道应该在 m{x|y}tics 中进行的分割数量所需的输出。

例如:如果我每两个单位就有一个 ytic,我需要“设置 mytics 8”。如果我每个单位都有一个 ytic,我需要“设置 mytics 4”。

那么,有什么方法可以获取自动放置的抽动之间的距离吗?或者甚至绘制抽动的数量?

最佳答案

要获取自动放置的抽动之间的距离,请使用以下代码(另存为 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

这应该相当于确定 ticstep 的内部 gnuplot 代码(请参阅 axis.c, line 677

要仅获取 ticstep,您可以使用 stats 获取相应的数据值:

stats 'file.txt' using 1 noutput
max_value = STATS_max
min_value = STATS_min
load 'ticstep.gp'
print ticstep

要获取绘制的抽动数量,您需要自动扩展轴限制(除非您使用设置自动缩放修复)。为此,您可以使用 unknown 终端进行绘图,以获得例如GPVAL_Y_MAXGPVAL_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)

关于gnuplot - 如何获取自动生成的 gnuplot tic 之间的距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25982518/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com