我正在使用peakutils Python包检测我的数据中的峰值( estimated.csv - found here的第二列)(单击链接)。
下面是我用来查找峰值的代码:
#/usr/bin/python -tt
import pandas as pd
import peakutils
estimated_data = pd.read_csv("estimated.csv", header=None)
col2 = estimated_data[:][1] # Second column data
print(col2[:]) # Print all the rows
index = peakutils.indexes(col2, thres=0.4, min_dist=1000)
print(index) 峰值检测工作得非常好。我想绘制所有检测到的峰值,就像在下面的教程中一样。
https://plot.ly/python/peak-finding/
但看起来plotly似乎不能离线工作。有没有不同的方式来使用像matplotlib这样的Python包
发布于 2017-06-12 23:26:54
使用matplotlib绘制峰值可以通过使用带有标记的图来完成。通过从peakutils函数找到的索引对数据进行索引。
import pandas as pd
import peakutils
import matplotlib.pyplot as plt
estimated_data = pd.read_csv("data/estimated.csv", header=None)
col1 = estimated_data[:][0] # First column data
col2 = estimated_data[:][1] # Second column data
index = peakutils.indexes(col2, thres=0.4, min_dist=1000)
plt.plot(col1,col2, lw=0.4, alpha=0.4 )
plt.plot(col1[index],col2[index], marker="o", ls="", ms=3 )
plt.show()

为了用一条线连接峰值(如评论中所要求的),on将简单地省略ls="",
plt.plot(col1[index],col2[index], marker="o", ms=3 )

https://stackoverflow.com/questions/44502658
复制相似问题