如何使用Python绘制所有峰值

2024-05-28 11:16:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用peakutilsPython包来检测数据中的峰值(第二列estimated.csv-foundhere(单击链接)。在

以下是我查找峰值的代码:

#/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在离线状态下似乎不起作用。使用Python包(如matplotlib)有不同的方法吗?在


Tags: csv数据代码importdataindex链接col2
1条回答
网友
1楼 · 发布于 2024-05-28 11:16:52

使用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()

enter image description here

为了将峰值与一条线连接起来(如注释中所要求的),on将简单地省略ls=""

^{pr2}$

enter image description here

相关问题 更多 >