Suppose I have data like red points below
I would like to interpolate/resample these points at black ticks.
At right the points are sparse and it is obvious to interpolate them linearly or with higher order polynomial.
But at left side points are denser, than ticks, so it seems to be wrong to interpolate them with any of this, because plot will jump and provide random values at ticks (green line). It looks better to average them near ticks first and then interpolate.
Is there any method/algorithm to do this automatically in case when data is both dense and sparse in different places?