I am trying to smooth the following data using python gaussian_kde however it is not working properly, it looks like the kde it is resampling for the distribution for the whole dataset instead of using a bandwidht for each point and giving the weights to do the smoothing
from scipy.stats import gaussian_kde
import matplotlib.pyplot as plt
import numpy as np
y=[ 191.78 , 191.59, 191.59, 191.41, 191.47, 191.33, 191.25 \
,191.33 , 191.48 , 191.48, 191.51, 191.43, 191.42, 191.54 \
,191.5975, 191.555, 191.52 , 191.25 , 191.15 , 191.01 ]
x = np.linspace(1 ,20,len(y))
kde= gaussian_kde(y)
kde.set_bandwidth(bw_method=kde.factor / 3)
fig, ax = plt.subplots(figsize=(10, 10))
ax.legend(loc='center left', bbox_to_anchor=(1.05, 0.5), frameon=False)
ax.scatter(x, y, color='black', label='data')
ax.plot(x,y,color='red')
ax.plot(x,kde(x))
Here it is the chart of the data
You can notice that the chart it is not smoothing the line