使用对数刻度基本上意味着绘制一个值的对数而不是值本身。该set logscale
命令告诉 gnuplot 自动执行此操作:
- 读取数据,仍然是线性世界,还没有对数
- 计算等距网格 (
smooth csplines
) 上的样条曲线,仍然是线性世界
- 计算并绘制对数 (
set logscale
)
关键点是等距网格。假设一个人选择set xrange [1E-9:10000]
和set samples 101
。在线性世界中,1e-9 与 10000 相比约为 0,生成的网格将是 1E-9 ~ 0, 100, 200, 300, ..., 9800, 9900, 10000。第一个网格点位于 0,第二个是 100,gnuplot 将在它们之间画一条直线。当随后绘制数字的对数时,这不会改变。
这就是您在问题中已经注意到的内容:您需要 10 倍以上的点才能获得较小指数的平滑曲线。
作为一种解决方案,我建议切换对数的计算和样条的计算。
# create some random test data, code "stolen" from @theozh (https://stackoverflow.com/a/66690491)
set print $Data
do for [p=-9:3] {
do for [m=1:9:3] {
print sprintf("%g %g", m*10**p, (1+rand(0))*10**(p/12.*3.-2))
}
}
set print
# this makes the splines smoother
set samples 1000
# manually account for the logarithms in the tic labels
set format x "10^{%.0f}" # for example this format
set format y "1e{%+03.0f}" # or this one
set xtics 2 # logarithmic world, tic distance in orders of magnitude
set ytics 1
# just "read logarithm of values" from file, before calculating splines
plot $Data u (log10($1)):(log10($2)) w p pt 7 ti "Data" ,\
$Data u (log10($1)):(log10($2)) ti "cspline" smooth cspline
这是结果:
