carminat (49) [Avatar] Offline
#1
I am plotting some scattered data, together with some linear fit f(x)=a*x+b.
I would like to display in the key the values of a and b automatically (i.e. without having to copy them from the file fit.log).

Any ideas?
philipp.janert (286) [Avatar] Offline
#2
1)
First of all, if you are only doing a linear fit, then you don't need the "fit" command at all.
Instead, you can get the information you need from the "stats" command, which populates
two variables (by default called STATS_slope and STATS_intercept) with the values for a and b.

2)
The second part of your question is how to get the values of variables displayed into the key.
Use "sprintf()" together with plot ... title:

plot "data" title sprintf( "%f", a ) with lines

3)
Keep in mind that the key is intended to describe the data, not to provide auxiliary information.
To display the values of variables, it might be more appropriate to use "set label". You can use
the "sprintf()" function again, or find some other way to force a number-to-string conversion:

a = 3.14
set label 1 '' . a at 0,0

Here, the concatenation of the numeric variable "a" to the empty string forces a conversion to
string.

carminat (49) [Avatar] Offline
#3
Thanks!

PS: I know the key is not the right place to put a label, but it's the easiest option in graphs produced on the fly, for personal use.
philipp.janert (286) [Avatar] Offline
#4
I agree, and I do it all the time, too. smilie