Gnuplot:水平键排序(转置)

Gnuplot: horizontal key ordering (transpose)

我有一个 9 行的图和一个 3x3 键。我的绘图命令涉及一个循环,因为我需要以特定顺序从各种数据文件中绘图。默认键设置似乎垂直堆叠行标题,我如何将其更改为水平排​​序(或转置键)?即当前显示的密钥如下:

1 4 7
2 5 8
3 6 9

我想:

1 2 3
4 5 6
7 8 9

下面的 MWE,我更愿意重新排序键而不是实际的情节循环。:

set terminal postscript eps enhanced size 17cm,13.125cm colour 18 "Helvetica"

set output 'MWETransposeKey.eps'

set xrange [0:1]
set xtics 1
set yrange [-1:1.5]
set ytics 1
set key top left box horizontal maxcols 3 width 2 spacing 1.5

# number of curves:
N=9.0
## sine function:
f(x,n)=sin((x-0.5*(n-1)/N)*(2*pi))

plot for [n=1:N] f(x,n) w l title sprintf("Line %d",n)

Key order is stacked vertically

我已经尝试过 invert 关键字,但是关键变成了:

3 6 9
2 5 8
1 4 7

Inverted key

修改后的答案:

它应该是 set key horizontal,但正如您指出的那样,它的行为方式与您希望的不一样。让我们称之为错误或缺失的功能。

解决方法:

虽然很麻烦,但可以使用 plot 命令的 keyentry 功能以您喜欢的任何顺序手动构造密钥。

plot for [n=1:N] f(x,n) w l notitle, \
     for [n in "1 4 7 2 5 8 3 6 9"] keyentry title sprintf("Line %d",int(n))

除了@Ethan 的始终有效的手动 keyentry 解决方案外,这里还有一个自动版本,以防您有不想复制的 headers 数据文件或 re-type 再次。 此解决方法只是转置键。

代码:

### workaround for transposing the order of the keyentries
reset session

$Data <<EOD
A     B     C     D     E     F     G     H     I     J     K     L
1.05  1.10  1.15  1.20  1.25  1.30  1.35  1.40  1.45  1.50  1.55  1.60
1.05  1.10  1.15  1.20  1.25  1.30  1.35  1.40  1.45  1.50  1.55  1.60
2.05  2.10  2.15  2.20  2.25  2.30  2.35  2.40  2.45  2.50  2.55  2.60
EOD

myMaxRow = 3
myMaxCol = 4

row(i) = (i-1)%myMaxRow
col(i) = (i-1)/myMaxRow   # here gnuplot's integer divison is desired
KeyTranspose(i) = row(i)*myMaxCol + col(i) +1

set key top left vertical maxrow myMaxRow maxcol myMaxCol

plot for [i=1:12] $Data u 0:i w lp ps 1.5 pt i lc i notitle, \
     for [i=1:12] $Data u (NaN) w lp ps 1.5 pt KeyTranspose(i) lc KeyTranspose(i) title columnhead(KeyTranspose(i))
### end of code

结果: