|
From: Tait <gnu...@t4...> - 2011-02-15 23:29:38
|
(Sorry this was delayed; I accidentally sent from the wrong address and it was rejected by the moderator. But having already written it, it seemed a shame not to send it.) > set term dumb > min=10**10 > plot 'disy.100' u ($3<min?min=$3:min=min,$1):3 > > set term x11 > plot 'disy.100' u 1:($3/min) > > and you easily see the idea I wrote it this way. I think this reflects a big > problem for me to understand deeply how gnuplot deals with datafile and how > it plots, which is obviously different from the standard programming > languages. Thanks for your in-depth explanation or references, First, are you familiar with C? The syntax is similar, and it is described in "help ternary". The ternary operator: (condition) ? true-expr : false-expr is a single-line if/then/else construct. If condition is true, then true-expr is evaluated. Otherwise, false-expr is evaluated instead. So consider: $3<min ? min=$3 : min=min If the third column is less than the value of the variable min, then assign this new value to min. Otherwise do a non-operation (of setting min equal to itself). The "plot... using ($3<min?min=$3:min=min,$1):3" means plot the third column as the y-coordinate, against the stuff in parenthesis as the x-coordinate. In recent gnuplot versions, multiple expressions can be evaluated for each line of the input file, by separating them with a comma. The stuff in parenthesis finds the minimum value of column 3 (and saves in it variable min), then evaluates $1, which just means the value of column 1. The first plot is output as text in the console, so you might not have seen it. It doesn't matter, because it's just a throwaway plot used to find the minimum value of column 3 anyway. The second plot is the one that matters. It plots your data file using 1:($3/min) which means plot column 3 divided* by min versus column 1. Another approach to this problem would be to use an external program/script to find the minimum value of column three. I often use Perl for these tasks. Others use sed/awk/shell scripts. We should probably develop some C programs for contrib to do common tasks like this. For example: filename="disy.100" c3min = `min_value_by_col.pl filename 3` set term X11 plot filename using 1:(($3+0.0)/c3min) * The division here is possibly integer division, depending on the values from column 3 of 'disy.100'. If you want to assure floating-point results from the division, you should instead: plot 'disy.100' using 1:((0.0+$3)/min) or something similar. Adding 0.0 will force promotion of $3 to a float type, which will in turn force the division to be a floating-point operation. |