问题描述
我生成了一个这样的图形,它测量透明管的内容,但是管的边缘却像这样,您可以在管的边缘看到峰值。关于如何避免这种情况的任何建议”额外的”山峰?欢迎任何建议。
管子的图像就是这个
解决方法
这实际上不是特定于matplotlib
的问题。根据我对您问题的理解,您希望保留红色峰,同时删除蓝色峰。此任务可以通过scipy.signal.find_peaks
完成,您可以指定一个高度值来控制算法发现的峰。以下是一些最低代码(改编自scipy docs):
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram
from scipy.signal import find_peaks
x = electrocardiogram()[2000:4000]
peaks,_ = find_peaks(x,height=0.5)
fig,ax = plt.subplots(1,1,figsize=(7.2,7.2))
ax.plot(x)
ax.plot(peaks,x[peaks],"x")
ax.axhline(y=0.5,ls="--",color="gray")