[英]Plot the peaks of a histogram
I'm trying to figure out how to plot the peaks of a simple histogram using scipy.signal.find_peaks
but the peaks found seem way off. 我试图弄清楚如何使用
scipy.signal.find_peaks
绘制简单直方图的峰,但发现的峰似乎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")
You should try: 你应该试试:
plt.plot(bin_edges[peaks], hist[peaks], "x")
find_peaks
gives you the indices of local maxima in the hist
signal. find_peaks
为您提供了局部最大值的指数在hist
信号。
The x-values
of your histogram are bin_edges
and the y-values
are given by hist
. 直方图的
x-values
是bin_edges
,而y-values
由hist
给出。 So you have to look for the indices given by peaks
in each of these series. 因此,您必须在每个系列中寻找由
peaks
给出的索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.