如何获得对数刻度图中的(自动)偏移量? [英] How to get (automatic) offsets in logscale plots?

查看:56
本文介绍了如何获得对数刻度图中的(自动)偏移量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选项设置偏移量对日志图无效.

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

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

自Gnuplot 5.2起,

The option set offsets has no effect on log plots.

For instance, both figures below have been generated with set offsets 0,2,0,0:

In order to obtain the same effect I'm currently setting fixed ranges instead of using autoscale, which is non-optimal, as the script is intended for generating plots from data in batch.

Since Gnuplot 5.2, we have '"set log" re-implemented as special case of "set nonlinear"', and set nonlinear makes use of two axis, as it 'is similar to the set link command except that only one of the two linked axes is visible', and, since the documentation also makes clear that 'The offsets only affect the x1 and y1 axes', it appears that instead of a bug this is expected behavior.

Question: Is there a simple way of obtaining a similar autoscaled offset for log plots?

I suppose one can make a dummy plot and use the data ranges for setting the axis ranges in the outputted plot, but is there a better way?

For the sake of completeness, minimum codes for generating the figures above are:

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

and

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

解决方案

As you already mentioned in your question, you can create a dummy plot and add your offset to the ranges.

The point is that you can get the GPVAL_... variables only after plotting. So, currently I don't see another way to create a dummy plot unless this offset for logarithmic axes will be implemented in gnuplot itself.

The following example is an attempt to make this replot maybe a bit easier to handle using macros and evaluate(), see help macros and help evaluate. Perhaps it is a bit of a simplification if you batch process many plots. Maybe somebody will find a way to shorten this a bit.

Of course, you can also set myRange = [*:*] for autorange and myOffsets will be added to the autorange limits.

Code:

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

Result:

这篇关于如何获得对数刻度图中的(自动)偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆