gnuplot - Does `set xrange [x_min:x_max]` limit the ranged used for function fit?

FreelanceConsultant picture FreelanceConsultant · Jun 30, 2015 · Viewed 11.2k times · Source

Simple question - the range drawn on a plot can be changed with the set xrange [x_min:x_max] command.

Does this command also limit the range used when fitting a function using the data fitting tools in gnuplot? Is there a way to manually specify the ranged used for function fits? (One guess might be the command every? Do I need to over-ride xrange using every?)

The reason I ask is that I am using xrange to plot outputs zoomed in on the low value x region to view transient behaviour more clearly, but I think this may be "slicing off" values from the function fitting at larger x values outside the xrange region selected?

Answer

user8153 picture user8153 · Dec 10, 2017

This is an old question, but the current answer is incorrect: the current settings of xrange does affect the range used for fitting if no explicit range is given as part of the fit command. This can be easily seen by a simple example: if you have a datafile test.dat that contains

1 1
2 2
3 3
4 4
5 6
6 8
7 10
8 12

and use a linear fit, you get

fit a+b*x "test.dat" via a,b
plot "test.dat" w p, a+b*x w l

enter image description here

and fit parameters (a,b)=(-1.42, 1.59). However, if you first set the xrange you get

set xrange [4:8]
fit a+b*x "test.dat" via a,b
plot "test.dat" w p, a+b*x w l

enter image description here

and fit parameters (a,b)=(-4,2).

This is at least the current behavior of gnuplot 5.2, but this old thread from 2009 suggests that this has been the behavior for quite some time.