【问题标题】:How to get (automatic) offsets in logscale plots?如何在对数刻度图中获得(自动)偏移量?
【发布时间】:2021-01-21 14:50:16
【问题描述】:

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

例如,下面两个图都是用set offsets 0,2,0,0生成的:

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

自 Gnuplot 5.2 起,we have '"set log" 重新实现为 "set非线性" 的特例',并设置了两个轴的非线性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

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

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

    关键是您只能在 绘图之后获得GPVAL_... 变量。 所以,目前我没有看到另一种创建虚拟图的方法,除非这个对数轴的偏移量将在 gnuplot 本身中实现。

    以下示例尝试使用macrosevaluate() 使此重新绘制更容易处理,请参阅help macroshelp evaluate。 如果您批量处理许多图,可能会有点简化。也许有人会想办法缩短一点。

    当然,您也可以将myRange = [*:*] 设置为自动量程,myOffsets 将添加到自动量程限制中。

    代码:

    ### 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
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多