What algorithm might Google Sheets use for a "smooth line chart"? (Not the trend line)

162 Views Asked by At

It's not a cubic spline as the line always passes through the data points. It's not a polynomial - I have mapped a 6th order polynomial over seven data points and it is very different. Bard admits to not knowing:"The moving average algorithm that Google Sheets uses to generate smooth line charts is not a simple weighted moving average algorithm.

"A simple weighted moving average algorithm would not go through all of the data points in the series."The moving average algorithm that Google Sheets uses to generate smooth line charts is not a simple weighted moving average algorithm. A simple weighted moving average algorithm would not go through all of the data points in the series." Here's the type of data I'm working with:

Raw data - not smoothed

And here's how Sheets interpolates it:Smoothed data I'm looking for a way to replicate the smoothing programatically in order to interpolate between the data points similarly to Sheets.

2

There are 2 best solutions below

6
On

Google Sheet smoothened test data:

It's definitely not cubic spline interpolation.

NB: cubic spline interpolation does go through all the points!

Piecewise quadratic does look quite similar, even if not exactly the same.

Cubic Hermite spline looks even closer (using scipy.interpolate.PchipInterpolator in Python).

0
On

It looks like a Catmull-Rom type of interpolant. At each point $P_i$, the slope is taken to be the slope of the line $P_{i-1} P_{i+1}$. Then, for each interval, you the two end-points and the two end-slopes, which you can fit with cubic curve.