Search code examples
layoutplotlabelgnuplothardcoded

gnuplot - "simulating" input to hardcode a coordinate


Let's say I want to print a label for every x coordinate I have but at fixed height, rather than at an offset to the point in question?

i.e I want to replace:

plot ... , '' u 1:2:(sprintf(...)) w labels offset char 1,1 notitle

with something like

plot ..., '' u 1:(fixed coordinate):(sprintf(...)) w labels notitle

Is there such a possibility?


Solution

  • Yes, that is possible, and it is pretty much what you specified. You can specify a column with the literal number, but when you use a parenthesized expression, gnuplot will interpret it as an expression to be computed (columns can be referred to by $1, $2, and so on in this expression).

    So, if you want to have the y coordinate fixed at 5 (for example), you can do

    plot datafile u 1:(5):(sprintf(...)) w labels notitle
    

    When reading this expression, gnuplot will interpret the unparenthesized 1 as a column specification, but will treat the literal number in parentheses as an expression to compute - in this case a very simple expression evaluating to 5.

    This same method can be used to transform the data to be plotted. For example, plot datafile u ($1*2):(sin($2)) will plot data at a point which has x coordinate equal to twice the value in column 1 and y coordinate equal to the sine of the value in column 2 - as long as it is in parentheses gnuplot will treat it as an expression to be evaluated for each point.

    See help using and help using examples for more information.