不使用 "first" 选项时的 gnuplot 奇怪行为

gnuplot strange behavior when not using "first" option

我在绘制水平线时遇到问题

...
set arrow 2 from graph 0, y(x) to x, y(x) nohead
...

为清楚起见,假设 x = 1 => y = 3 据我所知,这应该生成从 (0,3)(1, 3) 的一行。然而,第一个点 (0,3)y 坐标竟然出现在绘图之外的某个地方。但是如果我使用(根据 a post here

set arrow 2 from graph 0, first y(x) to x, y(x) nohead

然后它会产生我想要的输出。

有人可以用 first 向我解释上面的魔法吗?

值得一读 help coordinates 以了解不同的坐标系。简而言之,first坐标系是由x轴和y轴的当前范围定义的坐标系:图形左下角坐标为(xmin,ymin),右上角坐标为(xmax,最大)。在graph坐标系中,左下角始终为(0,0),右上角始终为(1,1),与两个轴的范围无关。

这是一个简短的例子:

set xrange [-4:4]
set yrange [-3:3]
set grid
set arrow 1 from first 0,0 to first 1,1 ls 1 lw 3
set arrow 2 from graph 0,0 to graph 1,1 ls 2 lw 3
plot 1/0 ti ""

紫色向量为箭头1,在first坐标系中从(0,0)到(1,1)。第二个向量是箭头2,在graph坐标系中从(0,0)到(1,1)。

将使用坐标系的默认规则是

If the coordinate system for x is not specified, first is used. If the system for y is not specified, the one used for x is adopted.

以及 set arrow

的特例

A coordinate system specifier does not carry over from the first endpoint description [to] the second.

听起来你想使用 first 坐标系,所以你不需要做任何事情:

set arrow from 0, y(x) to x, y(x)

当你使用

set arrow from graph 0, y(x) to x, y(x)

你用graph坐标系作为起点,first坐标系作为终点。

当你使用

set arrow from graph 0, first y(x) to x, y(x)

您使用 graph 坐标系作为起点的 x 坐标,并使用 first 坐标系作为其余坐标。如果 x 轴的范围从零开始,这将与对所有内容使用 first 坐标系相同。