Skip to content

Instantly share code, notes, and snippets.

@pavlin-policar
Created May 19, 2025 10:25
Show Gist options
  • Save pavlin-policar/6a6b48e30b2c4197689abf9c7128affc to your computer and use it in GitHub Desktop.
Save pavlin-policar/6a6b48e30b2c4197689abf9c7128affc to your computer and use it in GitHub Desktop.
def smooth_line(x, y, sigma=5, interp_points=300):
from scipy.ndimage import gaussian_filter1d
x_interp = np.linspace(x.min(), x.max(), interp_points)
# The gaussian filter assumes spacing 1, so we have to adjust sigma
interp_diff = x_interp[1] - x_interp[0]
effective_sigma = sigma / interp_diff
y_interp = np.interp(x_interp, x, y)
y_smooth = gaussian_filter1d(y_interp, sigma=effective_sigma)
return x_interp, y_smooth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment