Gnuplot - 绘制 - 第一行作为标签

Gnuplot - plot for - first row as labels

版本 gnuplot:5.4

我有以下格式的数据集:

Label1 Label2 Label3
1 2 3 
2 5 6

我想使用 plot 命令,因为列数不是静态的,我想使用数据集的第一行作为标签。

当我使用: plot for [i=2:dataset_columns] 'dataset.dat' using ():($i) with lines axes x1y1

错误:

warning: bad data on line 1 of file dataset.dat
Column number or datablock line expected

问题: 如何编辑我的命令来打印数据,如何使用第一行作为标签?

感谢您的帮助。

在 gnuplot 控制台中检查 help plot for。如果你读到最后你会看到:

If an iteration is to continue until all available data is consumed, use the symbol * instead of an integer . This can be used to process all columns in a line, all datasets (separated by 2 blank lines) in a file, or all files matching a template.

Examples:

  plot for [i=2:*] 'datafile' using 1:i with histogram
  splot for [i=0:*] 'datafile' index i using 1:2:3 with lines 
  plot for [i=1:*] file=sprintf("File_%03d.dat",i) file using 2 title file

代码:

### plot all columns until last column
reset session

$Data <<EOD
Label1 Label2 Label3
1 2 3 
2 5 6
EOD

plot for [col=2:*] $Data u 1:col w l title columnhead
### end of code

加法:(如果你有一个名为datafile.dat的数据文件)

Label1 Label2 Label3
1 2 3 
2 5 6

代码:

### plot all columns until last column
reset session

plot for [col=2:*] 'datafile.dat' u 1:col w l title columnhead
### end of code

结果: