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?
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
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
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.
set xrange [x_min:x_max]
does not affect the range used when fitting a function.
With the fit
command (the same holds for plot
) you can explicitly restrict the range to fit for a variable with the following syntax:
[{dummy_variable=}{<min>}{:<max>}]
For instance you can restrict range for the x axis with:
fit [min:max] f(x) "filename"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With