堆积线上的平滑线条绘制python matplotlib

时间:2018-04-22 23:38:31

标签: python matplotlib

我有以下代码来生成堆叠折线图。是否可以平滑线条?

y1, y2, y3, y4, y5, y6, y7= y1_dict.values(), 
y2_dict.values(), y3_dict.values(), y4_dict.values(), 
y5_dict.values(), y6_dict.values(), y7_dict.values()
fig, ax = plt.subplots()

ax.stackplot(y1_dict.keys(), y1, y2, y3, y4, y5, y6, y7) 
plt.xticks(y1_dict.keys(), times, rotation="vertical") 
#times holds str representations of minutes in 15 min intervals in a 24 hr period
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("title")
plt.show()

以下是下图的图片:

stacked line graph

1 个答案:

答案 0 :(得分:0)

您可以过滤数据来执行此操作。一个简单的选择就是平均过滤器。例如,我有以下数据。

enter image description here

然后我用长度为5均值的滤镜过滤它。我使用scipy的convolve函数来做到这一点。

from scipy.signal import convolve
smoothed = convolve(data, [1/5] * 5, mode='valid')

这导致了这个信号。

enter image description here