【问题标题】:Gnuplot: weird every behaviourGnuplot:每一个行为都很奇怪
【发布时间】:2018-11-23 15:21:13
【问题描述】:

我想绘制如下文件:

this is some header
that is written by the measurement software
for example it contains the date: 2018/1/1

column 1    column 2    column 3    column 4
1   12  13  13  14
2   15  15  15  15
3   10  12  13  15
4   9   9   8   8
5   7   9   10  11
6   6   6   6   6

所以有一个多行标题,用空行分隔数据。很简单,只需使用我想的every 命令。但是有一些问题(MWE):

reset

$testdata << EOD
this is some header
that is written by the measurement software
for example it contains the date: 2018/1/1

column 1    column 2    column 3    column 4
1   12  13  13  14
2   15  15  15  15
3   10  12  13  15
4   9   9   8   8
5   7   9   10  11
6   6   6   6   6
EOD

# set datafile separator "\t"
# set key autotitle columnhead
# set datafile commentschars "abcdefghijklmnopqrstuvwxyz"

# errors: bad data on line X:
# plot $testdata
# plot $testdata every ::1
# plot $testdata every ::2
# plot $testdata every ::3
plot $testdata every ::4

如果我只绘制没有every 的文件,我会收到bad data 错误(如预期的那样)。我的理解是我需要忽略前 4 行,因为它们只是文本,因此必须使用 plot $testdata every ::4,但这也忽略了前 3 个数据点,并且绘图从 x=4 开始。 可以使用every ::3,然后绘图从 x=3 开始。 使用every ::1every ::2 再次产生bad data 错误。

如果我取消注释set key autotitle columnhead,标题只会更改为“是”或“这是一些标题”(取决于datafile separator),所以根本不会忽略标题。此外,虽然现在 every ::2 有效(.. 并且情节从 x=2 开始),every ::1 仍然会产生错误。

我的目标是得到一个包含每个数据点的图,显然 + 使用列标题作为标题。我目前的解决方法是set datafile commentschars "abcdefghijklmnopqrstuvwxyz",但这会阻止我使用 columnhead-titles。是否有仅 gnuplot 的方法来处理此问题?我无法更改文件格式,因为它是测量设备的输出。另外,我知道像 awk 这样的工具,但我不是管理员,无法安装软件。这也应该避免,以允许在不同的机器上运行脚本。

非常感谢任何帮助! 非常感谢

【问题讨论】:

  • 使用skip 关键字来避免解释前几行,例如plot $testdata skip 4。使用every 选择数据仅在完整数据已被解析和解释后完成。

标签: header gnuplot head


【解决方案1】:

使用every 进行的数据过滤只有在整个数据被解析后才会进行。这就是您收到警告和错误的原因,因为第一行无法正确解析。

要在实际解析开始之前跳过某些行,请使用 skip 关键字:

$testdata <<EOD
this is some header
that is written by the measurement software
for example it contains the date: 2018/1/1

"column 1"    "column 2"    "column 3"    "column 4"
1   12  13  13  14
2   15  15  15  15
3   10  12  13  15
4   9   9   8   8
5   7   9   10  11
6   6   6   6   6
EOD

set key autotitle columnheader
plot $testdata skip 4 using 1:2 w lp

【讨论】:

  • 从来不知道skip 命令存在。非常感谢,成功了!
猜你喜欢
  • 2011-05-03
  • 2017-12-12
  • 1970-01-01
  • 2011-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-26
  • 1970-01-01
相关资源
最近更新 更多