如何在 gnuplot 中使用列标题的子字符串?
How to use a substring of the columnhead in gnuplot?
如何使用列标题的子字符串作为键?
以下简单示例:
代码:
### How to get a substring from columnhead?
reset session
$Data <<EOD
ABC.x ABC.y DEF.x DEF.y GHI.x GHI.y
11 21 31 41 51 61
12 22 32 42 52 62
13 23 33 43 53 63
14 24 34 44 54 64
15 25 35 45 55 65
EOD
set key top left
plot for [i=1:5:2] $Data u i:i+1 w lp title columnhead(i)
### end of code
结果:
我可以使用这两种语法变体:
... title columnhead
... title columnhead(i)
不过,现在我想跳过图例中的 .x
。
None 以下作品:
... title columnhead[1:3]
... title columnhead(i)[1:3]
... title substr(columnhead,1,3)
... title substr(columnhead(i),1,3)
... title sprintf("%s",columnhead)[1:3]
... title sprintf("%s",columnhead(i))[1:3]
... title (sprintf("%s",columnhead(i))."")[1:3]
... title (tmp=columnhead(i),tmp[1:3])
对于这些变体中的大多数,您将得到以下结果:
结果:
问题:这是为什么?如何解决?
显然,这已在 gnuplot 5.4.0 中解决,... title columnhead(i)[1:3]
似乎在那里工作。
尽管如此,这里还是尝试为 gnuplot 5.0.0 到 5.2.8 提供解决方法。也许,代码也可以适应旧的 gnuplot 版本。
代码:
### Get a substring from columnhead for gnuplot 5.0.0 - 5.2.8
reset session
$Data <<EOD
ABC.x ABC.y DEF.x DEF.y GHI.x GHI.y
11 21 31 41 51 61
12 22 32 42 52 62
13 23 33 43 53 63
14 24 34 44 54 64
15 25 35 45 55 65
EOD
# get the columnheads into a string
set table $Dummy
stats $Data u 0 nooutput
headers = ''
plot for [i=1:STATS_columns] $Data u (headers=headers." ".strcol(i),0) every ::0::0 w table
unset table
myTitle(i) = word(headers,i)[1:3]
set key top left
plot for [i=1:5:2] $Data u i:i+1 w lp title myTitle(i)
### end of code
结果:
如何使用列标题的子字符串作为键? 以下简单示例:
代码:
### How to get a substring from columnhead?
reset session
$Data <<EOD
ABC.x ABC.y DEF.x DEF.y GHI.x GHI.y
11 21 31 41 51 61
12 22 32 42 52 62
13 23 33 43 53 63
14 24 34 44 54 64
15 25 35 45 55 65
EOD
set key top left
plot for [i=1:5:2] $Data u i:i+1 w lp title columnhead(i)
### end of code
结果:
我可以使用这两种语法变体:
... title columnhead
... title columnhead(i)
不过,现在我想跳过图例中的 .x
。
None 以下作品:
... title columnhead[1:3]
... title columnhead(i)[1:3]
... title substr(columnhead,1,3)
... title substr(columnhead(i),1,3)
... title sprintf("%s",columnhead)[1:3]
... title sprintf("%s",columnhead(i))[1:3]
... title (sprintf("%s",columnhead(i))."")[1:3]
... title (tmp=columnhead(i),tmp[1:3])
对于这些变体中的大多数,您将得到以下结果:
结果:
问题:这是为什么?如何解决?
显然,这已在 gnuplot 5.4.0 中解决,... title columnhead(i)[1:3]
似乎在那里工作。
尽管如此,这里还是尝试为 gnuplot 5.0.0 到 5.2.8 提供解决方法。也许,代码也可以适应旧的 gnuplot 版本。
代码:
### Get a substring from columnhead for gnuplot 5.0.0 - 5.2.8
reset session
$Data <<EOD
ABC.x ABC.y DEF.x DEF.y GHI.x GHI.y
11 21 31 41 51 61
12 22 32 42 52 62
13 23 33 43 53 63
14 24 34 44 54 64
15 25 35 45 55 65
EOD
# get the columnheads into a string
set table $Dummy
stats $Data u 0 nooutput
headers = ''
plot for [i=1:STATS_columns] $Data u (headers=headers." ".strcol(i),0) every ::0::0 w table
unset table
myTitle(i) = word(headers,i)[1:3]
set key top left
plot for [i=1:5:2] $Data u i:i+1 w lp title myTitle(i)
### end of code
结果: