Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot title variables separated by text

Tags:

gnuplot

I am trying to add text+variable+text+variable into the title of the plot in gnuplot batch file.

I have variables lines and last containing numbers(1 and 350) and the code Ive got is:

set title sprintf("Secondary structure CA IX residues".first,"to".lines) 

It prints: "Secondary structure CA IX1".

Can anyone help how to write this correctly, so that it will write Secondary structure CA IX residues 1 to 350 with gaps?

like image 242
Michal Škultéty Avatar asked Aug 18 '26 21:08

Michal Škultéty


2 Answers

You have two options:

  1. Use the . operator to concatenate your variables into strings:

    set title "Secondary structure CA IX residues " . first . " to " . lines
    

    I have added in spaces between the " and . for clarity, these will not be featured in the output. You are responsible for adding in the appropriate spaces in the string sections.

  2. Use sprintf as it was intended:

    set title sprintf("Secondary structure CA IX residues %d to %d", first, lines)
    

    The first argument to sprintf is a format string, which should not contain any variables. Placeholders (such as %d) are used to indicate the positions that variables should be inserted. Subsequent arguments to the function are the variables to be inserted. As your two variables appear to be integers, %d is the appropriate format specifier to use.

like image 76
Tom Fenech Avatar answered Aug 22 '26 12:08

Tom Fenech


If you need spaces, insert them!

first = 1
lines = 350
set title sprintf("Secondary structure CA IX residues %d to %d", first, lines)
like image 23
Christoph Avatar answered Aug 22 '26 11:08

Christoph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!