magfan
magfan

Reputation: 463

It is not possible to extract specific columns of data in gnuplot based on a specific heading

In the following Gnuplot script, I want to extract values from a specific table. This works fine for columns that contain numbers but I cannot extract the path from the column "Measure:volume". What needs to be changed to solve this problem?

reset

set datafile missing "NaN"
set datafile columnheader

$Data << EOD
Measure:volume         lh_01    rh_01  
sub_001/2001476309_t1  7030.26  7353.44
sub_002/2026003745_t1  7652.64  8566.62
sub_003/0119972330_t1  6938.74  7489.41
sub_004/2022130250_t1  6619.97  6224.74
sub_005/2105171757_t1  7472.23  8635.48
sub_006/2060302238_t1  6612.52  7347.70
sub_007/2021110417_t1  7049.64  7137.09
sub_008/0152544707_t1  8327.11  8745.67
sub_009/0219080602_t1  7924.66  8694.33
sub_010/2018143733_t1  7605.58  8072.01
EOD

path_column = "Measure:volume"
left = "lh_01"
right = "rh_01"

set table $Temp
plot $Data using path_column:left:right with table
unset table

print $Temp

### End of script

The result looks like this:

gnuplot> load "test_plot_data.gp"
 nan     7030.26         7353.44
 nan     7652.64         8566.62
 nan     6938.74         7489.41
 nan     6619.97         6224.74
 nan     7472.23         8635.48
 nan     6612.52         7347.7
 nan     7049.64         7137.09
 nan     8327.11         8745.67
 nan     7924.66         8694.33
 nan     7605.58         8072.01

gnuplot> 

Upvotes: 1

Views: 33

Answers (1)

theozh
theozh

Reputation: 26123

Ok, now I see what you meant. Since the column withthe header "Measure:volume" is a column with string values, of course you have to use stringcolumn() or shorter strcol() (check help strcol).

Hence, the following should do the job. Don't forget the parantheses around (strcol(path_column)).

path_column = "Measure:volume"
plot $Data u (strcol(path_column)):left:right with table

Upvotes: 1

Related Questions