Gnuplot 按角度选项拉伸椭圆

Gnuplot stretched ellipse by angle option

我想用gnuplot画一个椭圆。它应该稍微倾斜,因此我使用角度选项。 但是角度会影响椭圆的大小。我的文档有问题吗?

参见以下示例:

set output "test.pdf"
set obj ellipse center 5,0.5 size 4,0.2 angle 20
set xrange [0:10]
plot sin(x)

添加的两个png显示了我的结果。我使用的是 5.2.8 版本。

编辑: Ethan 的解决方案当然是可行的方法。 请记住,如果您没有 set size ratio -1,一行,例如像plot x不会出现在与x轴成45°角的地方。

可能,最简单的解决方案是 set size ratio -1 使 x 轴和 y 轴具有相同的比例。如果您需要不同的规模,应该有不同的解决方案。

代码:

### draw tilted ellipse with same proportions
reset session

set size ratio -1
set obj 1 ellipse center 5,0.5 size 4,0.2 angle 0  fc "red"
set obj 2 ellipse center 5,0.5 size 4,0.2 angle 20 fc "green"
set obj 3 ellipse center 5,0.5 size 4,0.2 angle 45 fc "blue"
set obj 5 ellipse center 5,0.5 size 4,0.2 angle 90 fc "magenta"

set xrange [0:10]
set yrange [-3:3]
plot sin(x)
### end of code

结果:

如果您希望椭圆的比例在旋转后保持不变,您必须以相同的单位给出长径和短径,例如“单位 xx”或“单位 yy”。在这里,我使用 x 坐标根据 4:1 与 major:minor 轴的比率来定义椭圆。

set obj 1 ellipse center 5,0.5 size 4,1 fs empty bo lc "blue"  angle 0   units xx
set obj 2 ellipse center 5,0.5 size 4,1 fs empty bo lc "red"   angle 20  units xx
set obj 3 ellipse center 5,0.5 size 4,1 fs empty bo lc "green" angle 40  units xx
set xrange [0:10]
plot sin(x)

如果允许输出到虚拟文件,下面的解决方案如何。

set terminal pdf size 10cm,10cm

set xrange [0:10]

# dummy plotting
set output "dummy.pdf"
plot sin(x)

factor =  real(GPVAL_X_MAX - GPVAL_X_MIN)/real(GPVAL_Y_MAX-GPVAL_Y_MIN) \
        * real(GPVAL_TERM_YMAX - GPVAL_TERM_YMIN)/real(GPVAL_TERM_XMAX - GPVAL_TERM_XMIN)

# real plotting
set output "test.pdf"
set obj ellipse center 5,0.5 size 4,factor*0.2 angle 20 unit xx
replot

在此脚本中,x 轴和 y 轴之间可见单位长度的比率是使用由虚拟绘图确定的变量 GPVAL_* 计算的。将它乘以椭圆的垂直轴并使用 'unit xx' 与 Ethan 的答案相同,你可能会得到你想要的数字。

如果您使用的是 UNIX(类)系统,请将 'set output "dummy.pdf"' 替换为

set output "/dev/null"