簡體   English   中英

find_peaks() 使峰正確,但將 plot 向左擠壓

[英]find_peaks() put the peaks correct, but squeezed the plot left benear

我想通過 scipy 庫檢測曲線中的峰值,它是 function find_peaks()。
如果我 plot 在我的腳本中沒有 find_peaks() 函數的曲線,它將按預期繪制。
但是如果我在我的腳本中使用 find_peaks() function plot 會顯示這種意外行為。
任何想法這里出了什么問題都值得贊賞。
多謝。

如果我 plot 沒有 find_peaks() 函數的曲線,它按預期繪制:

正常情節

但是,如果我使用 find_peaks() function plot 會顯示這種意外行為:

壓縮情節

我使用此源代碼作為壓縮的 plot 顯示:

import pandas as pd
import numpy as np
from scipy.signal import find_peaks


"""Read the file

"""
path = '../data/accelerometer/Wrist-Accelerometer-X-Axis-UpDown.csv'


"""Define the variables

"""
w = data['elapsed (s)']
x = data['x-axis (g)']


"""Plot the data

"""
fig, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(8, 4))


ax1.plot(w, x, marker='.')
ax1.set_title('UpDown movement: Behaviour of x-axis')
ax1.set_xlabel('$Datapoints$')
ax1.xaxis.set_major_locator(plt.MultipleLocator(0.5))
ax1.set_ylabel('$Acceleration \n on x-axis (g)$')
ax1.yaxis.set_major_locator(plt.AutoLocator())
peaks, _ = find_peaks(x, -2, 0, prominence=1, distance=1)
ax1.plot(peaks, x[peaks], 'x', markersize=8)

plt.show()

這回答了我的問題:由於缺少尺寸,我將它們堆疊在下面。

  • 代碼中的原始行:

    ax1.plot(峰,x[峰],'x',markersize=8)

  • 代碼中的正確行:

    ax1.plot(w[peaks], x[peaks], 'x', markersize=8)

  • 結果:

預期=給定

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM