gnuplot

How do I create a variable in gnuplot that contains an entire table?


How is it possible to include a header row in the variable $Table and retain the first column of $Data (Strings)? $Table should contain a complete table, just like $Data.

reset session

$Data <<EOD
Temp    ST_01       ST_02       ST_03       ST_04
ag7     -0.0295167  0.0553285   0.00883727  0.392553
bc9     -0.0513702  0.0355596   -0.0165404  0.252816
cc9     -0.0303508  -0.00354388 0.0428582   0.0882037
cd3     -0.0239757  -0.0363891  0.0227775   0.270722
EOD

set table $Table
plot $Data u (sprintf("%f\t%f",column("ST_01")/column("ST_02"),column("ST_03"))) w table
unset table

print $Table

Solution

  • $Data <<EOD
    Temp    ST_01       ST_02       ST_03       ST_04
    ag7     -0.0295167  0.0553285   0.00883727  0.392553
    bc9     -0.0513702  0.0355596   -0.0165404  0.252816
    cc9     -0.0303508  -0.00354388 0.0428582   0.0882037
    cd3     -0.0239757  -0.0363891  0.0227775   0.270722
    EOD
    
    set print $Table
    print "Temp     St1/St2    St3"
    unset print
    
    # Make sure the 1st line of $Data is not treated as data values
    set datafile columnheader
    
    set table $Table append
    plot $Data using (strcol(1)) : (column("ST_01")/column("ST_02")) : (column("ST_03")) with table
    unset table
    
    print $Table
    

    Output:

    Temp    St1/St2          St3
    ag7      -0.533481       0.00883727
    bc9      -1.44462        -0.0165404
    cc9      8.56429         0.0428582
    cd3      0.65887         0.0227775