Reputation: 465
I know to fit 2D data has z value between [-1:4] in gnuplot is
f(x)=a*x+b
fit [][-1:4] f(x) "data"
but for 3D data , if I only want to fit data when f(x) has value between [-1:4]
f(x)=a*x+b*y+c
fit [][-1:4] f(x) "data"
fit [][][-1:4] f(x) "data"
are both wrong. why ?
Upvotes: 2
Views: 2954
Reputation: 48390
I am not sure, if the range behaviour you describe with the 2D fit is actually intended, because it does not work with the gnuplot development version. And according to the documentation, the range specifications for the fit
command apply only to the dummy variables (i.e. x
and y
). So it might be, that your first fit command works only because of a bug, which is a feature for you.
To limit the z
-range, you can set all values outside the desired range to 1/0
, which results in an undefined data point which is then ignored:
f(x, y) = a*x + b*y + c
zmin = -1
zmax = 4
fit f(x, y) "data" using 1:2:($3 < zmin || $3 > zmax ? 1/0 : $3):(1) via a,b,c
Note, that your function must be defined for two dummy variables x
and y
, and you must have the via
statement, which is missing in all of your examples.
To fit a function with two independent variables, z=f(x,y), the required format is
using
with four items, x:y:z:s. The complete format must be given---no default columns are assumed for a missing token. Weights for each data point are evaluated from 's' as above. If error estimates are not available, a constant value can be specified as a constant expression (seeplot datafile using
), e.g.,using 1:2:3:(1)
.
Upvotes: 2
Reputation: 1
This plots a plane in 3D, not a line. I was confused until I zoomed out and realized. Try the below dataset of 4 points. 'Set autoscale' to make sure you see the whole image. Or just read the fit.log file and realize the errors are high indicating a poor fit.
377.4202 -345.5518 2.1142
377.4201 -345.5505 2.5078
377.4206 -345.556 2.8359
377.4288 -345.5555 3.2109
Upvotes: 0