Search code examples
plotgnuplotleast-squaresfunction-fitting

gnuplot - How to fit a function every N data points


I am using gnuplot and the function fitting facilities to perform least squares fitting to some of my data.

I have many data points (sometimes tens of millions) and hence fitting to all data points is impossible. (Or at least too slow to be practical.)

It is possible to plot data points with the keyword every (EDIT: Should be pointinterval not every!) followed by an integer, N, to plot only every other Nth point.

eg plot 'data.csv' using 1:2 pointinterval 1000 plots every thousandth data point. Useful for when plotting 10's of millions of points - you can't see anything useful otherwise.

Is there a similar way of doing this with fitting, ie, fit only every 1000'th point?

I tried fit 'data.csv' f(x) using 1:2 pointinterval 1000 via a,b where a and b are parameters of my f(x) - but I just get an error: ';' expected.

I also tried googling this and reading the documentation for gnuplot plotting but didn't find anything.

Alternatively, I could change my program code to only write every 1000th point to datafile, but then I will have to have 2 lots of datafiles - one with all the points and one with 1 in every 1000 data points... which seems kind of wasteful.

Edit: I am not sure why I thought every was the correct syntax for this. Turns out it should be pointinterval (pi short) followed by an integer.

However, this only works for plotting, not function fitting, so the question is still open.


Solution

  • Note for future: use every syntax