scrollintoview animation

In most modern browsers (Chrome and Firefox, but not Safari, UC, or IE) you can pass options in an object to .scrollIntoView(). Try this: elm.scrollIntoView({ behavior: ‘smooth’, block: ‘center’ }) Other values are behavior: ‘instant’ or block: ‘start’ or block: ‘end’. See https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView

Smoothing a hand-drawn curve

You can reduce the number of points using the Ramer–Douglas–Peucker algorithm there is a C# implementation here. I gave this a try using WPFs PolyQuadraticBezierSegment and it showed a small amount of improvement depending on the tolerance. After a bit of searching sources (1,2) seem to indicate that using the curve fitting algorithm from Graphic … Read more

NumPy version of “Exponential weighted moving average”, equivalent to pandas.ewm().mean()

I think I have finally cracked it! Here’s a vectorized version of numpy_ewma function that’s claimed to be producing the correct results from @RaduS’s post – def numpy_ewma_vectorized(data, window): alpha = 2 /(window + 1.0) alpha_rev = 1-alpha scale = 1/alpha_rev n = data.shape[0] r = np.arange(n) scale_arr = scale**r offset = data[0]*alpha_rev**(r+1) pw0 = … Read more

Smoothing data from a sensor

The simplest is to do a moving average of your data. That is, to keep an array of sensor data readings and average them. Something like this (pseudocode): data_X = [0,0,0,0,0]; function read_X () { data_X.delete_first_element(); data_X.push(get_sensor_data_X()); return average(data_X); } There is a trade-off when doing this. The larger the array you use, the smoother … Read more

Smooth GPS data

Here’s a simple Kalman filter that could be used for exactly this situation. It came from some work I did on Android devices. General Kalman filter theory is all about estimates for vectors, with the accuracy of the estimates represented by covariance matrices. However, for estimating location on Android devices the general theory reduces to … Read more

Plot smooth line with PyPlot

You could use scipy.interpolate.spline to smooth out your data yourself: from scipy.interpolate import spline # 300 represents number of points to make between T.min and T.max xnew = np.linspace(T.min(), T.max(), 300) power_smooth = spline(T, power, xnew) plt.plot(xnew,power_smooth) plt.show() spline is deprecated in scipy 0.19.0, use BSpline class instead. Switching from spline to BSpline isn’t a … Read more