gpt4 book ai didi

gnuplot - 如何在对数标度图中获得(自动)偏移量?

转载 作者:行者123 更新时间:2023-12-04 04:21:30 24 4
gpt4 key购买 nike

set offsets 选项对日志图没有影响。

例如,下面的两个图都是使用设置偏移量 0,2,0,0 生成的:

enter image description here enter image description here

为了获得相同的效果,我目前正在设置固定范围而不是使用自动缩放,这不是最佳选择,因为该脚本旨在从数据批量生成绘图。

从 Gnuplot 5.2 开始,we have '“设置日志”重新实现为“设置非线性”的特例',并设置非线性 makes use两个轴,因为它'类似于 set link命令,除了两个链接轴中只有一个可见',而且,由于文档还makes clear偏移量仅影响 x1 和 y1 轴”,这似乎不是错误,而是预期的行为。

问题:是否有一种简单的方法可以为对数图获取类似的自动缩放偏移量?

我想可以制作一个虚拟图并使用数据范围来设置输出图中的轴范围,但有没有更好的方法?

为了完整起见,生成上述数字的最少代码是:

set terminal pngcairo size 250,250
set output "1.png"
set offsets 0,2,0,0
plot [0.1:1] 1/x

set terminal pngcairo size 250,250
set output "2.png"
set logscale
set offsets 0,2,0,0
plot [0.1:1] 1/x

最佳答案

正如您在问题中已经提到的,您可以创建一个虚拟图并将您的偏移量添加到范围。

重点是您只能在绘图之后 获取GPVAL_... 变量。因此,目前我看不到另一种创建虚拟图的方法,除非这个对数轴的偏移量将在 gnuplot 本身中实现。

以下示例尝试使用macrosevaluate() 使重绘更容易处理,请参阅help macros帮助评估。如果您批处理许多地 block ,可能会有点简化。也许有人会找到一种方法来缩短它。

当然,你也可以设置myRange = [*:*]为autorange,myOffsets将被添加到autorange limits。

代码:

### offsets for logarithmic scale
reset session
set term pngcairo size 300,300

SetMyOffsets(n) = sprintf("[%g:%g][%g:%g]", \
GPVAL_X_MIN-word(myOffsets,1), \
GPVAL_X_MAX+word(myOffsets,2), \
GPVAL_Y_MIN-word(myOffsets,4), \
GPVAL_Y_MAX+word(myOffsets,3))

GenerateOutput = 'set output myOutput; \
eval(myPlot); \
set output; \
set output myOutput; \
myRange=SetMyOffsets(0); \
eval(myPlot); \
set output'

# first plot with linear x-axis
myRange = '[0.1:1]'
myPlot = 'plot @myRange 1/x'
myOffsets = '0 2 0 0' # left right top bottom
myOutput = "Linear.png"
@GenerateOutput

# second plot with log x-axis
set logscale
myRange = '[0.1:1]'
myPlot = 'plot @myRange 1/x'
myOffsets = '0 2 0 0' # l r t b
myOutput = "Logarithmic.png"
@GenerateOutput

### end of code

结果:

enter image description here enter image description here

关于gnuplot - 如何在对数标度图中获得(自动)偏移量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59162660/

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