Reputation: 127
Version of gnuplot:5.4
I have dataset in format:
Label1 Label2 Label3
1 2 3
2 5 6
I want to use plot for command, because number of columns isnt static and I want to use first row of dataset as labels.
When i use:
plot for [i=2:dataset_columns] 'dataset.dat' using ($1):($i) with lines axes x1y1
Error:
warning: bad data on line 1 of file dataset.dat
Column number or datablock line expected
Question: How to edit my command to get data printed, how to use first row as labels?
Thank you for your help.
Upvotes: 0
Views: 1107
Reputation: 25734
In gnuplot console check help plot for
. If you read it to the end you will see:
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
Code:
### 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
Addition: (in case you have a datafile named datafile.dat
)
Label1 Label2 Label3
1 2 3
2 5 6
Code:
### plot all columns until last column
reset session
plot for [col=2:*] 'datafile.dat' u 1:col w l title columnhead
### end of code
Result:
Upvotes: 2