微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

具有自定义范围的 Gnuplot 偏移量 (v5.4)

如何解决具有自定义范围的 Gnuplot 偏移量 (v5.4)

与 v5.2 相比,我对偏移量在 gnuplot v5.4 中的工作方式有疑问。 我尝试制作下图(v5.2):

example_5.2

为了创建这个图表,我使用了以下代码...

set style line 1 lc rgb '#808080' lt 1 lw 2
set border 0 ls 1
set arrow from 0,graph 0 to 5,graph 0 nohead front ls 1
set arrow from graph 0,first 0 to graph 0,first 5 nohead front ls 1
set xtics nomirror
set ytics nomirror
set lmargin 10
set bmargin 3.5
set xrange [0:5]
set yrange [0:5]
set offsets graph 0.1,graph 0.1,graph 0.1
plot 'example.txt'

...和数据。

#x  y
0   3.88222
1   4.20754
2   4.424
3   2.41443
4   1.95107
5   2.79098

在 v5.4 中,此代码生成没有偏移量的图形:

example_5.4

不幸的是,文档没有解决自定义范围。 我不确定这是否是一个错误、我的代码有问题,或者是否在 gnuplot v5.4 中完全删除了使用偏移量和自定义范围的功能

先谢谢你!

解决方法

“偏移”的文档部分在 gnuplot 版本 5 中不好。

我的理解是当前(5.4 版)的行为是

  • offsets 只影响自动缩放
  • 明确的轴范围优先于自动缩放,因此如果该轴有明确的范围,则偏移量无效
  • 查询中显示的绘图样式最好在 gnuplot 5.4 中使用关键字 rangelimited 实现,例如set tics rangelimited 如果你想在所有轴上都这样做

下面的命令在 gnuplot 5.0 和 5.2 版本中的工作方式与它们在 5.4 版本中的工作方式相同,所以我认为这个例子不是两个版本之间的突然变化,而是版本 4 之间细微差异的逐渐积累和 5. 我将提交一个错误报告,指出当前文档部分关于“偏移”的不足。

修改后的代码

# Modified for gnuplot version 5.4
set xtics rangelimited nomirror
set ytics rangelimited nomirror
set border 3
set offsets graph 0.1,graph 0.1,graph 0.1
plot 'example.txt' with points

enter image description here

,

一个奇怪的观察,我可以重现。以下进一步最小化的代码在 gnuplot 5.2 和 gnuplot 5.4 中的行为不同

reset session
set xrange[0:5]
set yrange[0:5]
set offset graph 0.1,graph 0.1
plot x

我不确定为什么会有所不同。以下有点麻烦的解决方法将在 gnuplot 5.2 中导致相同的结果。和 gnuplot 5.4 与重新绘图的成本。但我希望会有一个更简单的解决方案,目前对我来说并不明显。也许 gnuplot 5.4 中有另一个设置可以“恢复”这种 5.2 行为。

代码:

### "manual" offset for gnuplot 5.4
reset session

$Data <<EOD
#x  y
0   3.88222
1   4.20754
2   4.424
3   2.41443
4   1.95107
5   2.79098
EOD

set style line 1 lc rgb '#808080' lt 1 lw 2
set border 0 ls 1
set arrow from 0,graph 0 to 5,graph 0 nohead front ls 1
set arrow from graph 0,first 0 to graph 0,first 5 nohead front ls 1
set xtics nomirror
set ytics nomirror
set lmargin 10
set bmargin 3.5

set xrange [0:5]
set yrange [0:5]

xRange(a)  = GPVAL_X_MAX  -GPVAL_X_MIN
yRange(a)  = GPVAL_Y_MAX - GPVAL_Y_MIN
xOffMin(a) = GPVAL_X_MIN - a*xRange(a)
xOffMax(a) = GPVAL_X_MAX + a*xRange(a)
yOffMin(a) = GPVAL_Y_MIN - a*yRange(a)
yOffMax(a) = GPVAL_Y_MAX + a*yRange(a)

plot $Data

set xrange [xOffMin(0.1):xOffMax(0.1)]   # graph 0.1 
set yrange [yOffMin(0.1):xOffMax(0.1)]   # graph 0.1 

replot
### end of code

结果:(gnuplot 5.2 和 gnuplot 5.4)

enter image description here

添加:

好吧,您正在设置 固定 x 和 y 范围,然后添加 10% 的额外偏移。因此,您可以直接设置 set xrange[-0.5:5.5]set yrange[-0.5:5.5],也可以按照下面的代码进行计算。但是,我同意如果它在 gnuplot 5.2 中工作,您设置范围然后添加 10% 的额外偏移会更方便。

reset session
xMin=0
xMax=5
yMin=0
yMax=5
OffLeft   = 0.1
OffRight  = 0.1
OffTop    = 0.1
OffBottom = 0.1
xRange = xMax-xMin
yRange = yMax-yMin

set xrange[xMin-OffLeft  *xRange : xMin+OffRight*xRange]
set yrange[xMin-OffBottom*yRange : yMin+OffTop  *yRange]

plot x

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。