1

I have a plot that looks like this ( the red line is what I am trying to achieve ):

enter image description here

sns.lineplot(x = 'day_id', y = 'sales', data = df)
plt.axvline('2021-08-28',0,1, ls = '--', lw = 3, c ='black')
plt.text('2021-08-28',5,'2021-08-28', ha='center', va='center',
         bbox={'facecolor':'white','alpha':1,'edgecolor':'none','pad':1})

It's just some sales over time grouped by week. I am trying to fit that red line to show the overall behaviour of the sales in time as a smooth line. I am not sure how I should do that.

I've checked this answer which uses interpolate but as my x is a timestamp that did not workout for me.

from scipy.interpolate import make_interp_spline, BSpline

# 300 represents number of points to make between T.min and T.max
xnew = np.linspace(df.sales.min(), df.sales.max(), 300) 

spl = make_interp_spline(df.day_id, df.sales, k=3)  # type: BSpline
power_smooth = spl(xnew)

plt.plot(xnew, power_smooth)
plt.show()

enter image description here

How can I have a line that represents the swing of the sales in time, I am not sure what exactly it is called.

Jonas Palačionis
  • 4,591
  • 4
  • 22
  • 55

0 Answers0