绘制直方图的峰

时间:2019-07-30 18:01:08

标签: python matplotlib scipy

我试图弄清楚如何使用scipy.signal.find_peaks绘制简单直方图的峰,但是发现的峰似乎很远。

ages = np.array([10, 5, 22, 13, 50, 45, 67, 30, 21, 34, 60, 67, 89, 45, 45, 65])
hist, bin_edges = np.histogram(ages, 10)
bin_edges = bin_edges[1:]

plt.plot(bin_edges, hist)
peaks, _ = find_peaks(hist)
plt.plot(ages[peaks], peaks, "x")

plotted peaks

1 个答案:

答案 0 :(得分:2)

您应该尝试:

plt.plot(bin_edges[peaks], hist[peaks], "x")

find_peaks为您提供hist信号中局部最大值的索引。

直方图的x-valuesbin_edges,而y-valueshist给出。因此,您必须在每个系列中寻找peaks给出的索引。