如何使用Python将“阶跃函数”曲线更改为平滑线?

时间:2018-08-14 19:21:15

标签: python matplotlib

我是Python的新手,我试图使图表看起来更平滑(噪音更少),但是我使用的语法使图形看起来像阶跃函数而不是平滑曲线。

我已经研究并尝试了各种解决问题的方法(即滚动平均和插值法),但是我遇到了很多问题。我认为是因为我正在调用数据框。

如果有人可以帮助,那就太好了!

xls = pd.ExcelFile('2. TEDs.xlsx')
df1 = pd.read_excel(xls, 'Sheet 1')
df2 = pd.read_excel(xls, 'Sheet 2')

df1['Duration']=(df1.index.values)*5/60
df2['Duration']=(df2.index.values)*5/60

df1['B-SIDE AVERAGE'] = df1[['6 (U)','M','Y','Z','K','G','W','8 (U)','11 (U)','O','15 (U)','N','B','2 (U)','E','F','A','+','/','I','1 (U)']].mean(axis=1)
df2['B-SIDE AVERAGE'] = df2[['6 (O)','M','Y','Z','K','G','W','8 (O)','11 (O)','O','15 (O)','N','B','2 (O)','E','F','A','+','/','I','1 (O)']].mean(axis=1)

fig, ax1 = plt.subplots(figsize=(10, 8))
ax1.plot(df1['Duration'], df1['B-SIDE TRIM AVERAGE'], color = (1.,0.,0.), label = 'UNOCCUPIED')
ax1.plot(df2['Duration'], df2['B-SIDE TRIM AVERAGE'], color = (0.,0.,1.), label = 'OCCUPIED')
ax1.set_xlabel('Duration (min)')
ax1.set_xlim(0,max(df1['Duration']))
ax1.set_ylabel('Deg. C')
plt.title('Temperature Average', fontsize = 14)
ax1.legend(bbox_to_anchor=(0.817, 0.976), loc='center',
       ncol=2, mode="", borderaxespad=0.)
ax1.grid()
plt.show()

Chart with step function like curve

0 个答案:

没有答案