将X轴值添加到图中的峰

发布于 2025-01-23 03:51:01 字数 482 浏览 1 评论 0原文

亲爱的stackoverflow家族,

我一直在尝试将X轴值放在图中检测到的峰的顶部或​​位于图中检测到的峰值。基本上,首先,我使用该函数在频谱中找到峰。然后,我想使用这些与峰一致的X轴值,而不仅仅是放置“ X”或任何类型的符号。

感谢您的任何帮助或建议。

代码;

    peaks, properties = find_peaks(meanMat1, prominence=1, width=4)
    peak_coordinates = list(zip(Ram[peaks], a[peaks])) 
    
    print(peak_coordinates)
   
    d=Ram[peaks]
    e=c[peaks]
    
    ax.plot(d, e, "x", color = "xkcd:orange")

(在这里,D和E是被检测到的峰。D和E分别给出X轴和Y轴值(在NP.Array中)。)。

Dear StackOverflow family,

I have been trying to put the x-axis values next to, or at the top of the peaks that are detected in the graph. Basically, first I used the function to find the peaks in the spectrum. Then, I want to use these x-axis values that coincide with the peaks, not just only putting "x", or any kind of symbol.

Thank you for any kind of help or suggestion.

The codes;

    peaks, properties = find_peaks(meanMat1, prominence=1, width=4)
    peak_coordinates = list(zip(Ram[peaks], a[peaks])) 
    
    print(peak_coordinates)
   
    d=Ram[peaks]
    e=c[peaks]
    
    ax.plot(d, e, "x", color = "xkcd:orange")

(Here, d and e are the peaks that are detected. d and e give x-axis and y-axis values (in np.array), respectively.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃→可爱长大的 2025-01-30 03:51:01

您可以使用matplotlib 要添加一个字符串,或者在您的特殊情况下,x轴值,将x轴值,x(您的示例中的d)添加到轴上)y(e在您的示例中)在数据坐标中。

import matplotlib.pyplot as plt
from scipy.signal import find_peaks
import numpy as np

# curve setup
x = np.linspace(0,10*np.pi,200)
fx = np.sin(2*x)*np.cos(x/2)*np.exp(-0.1*x)

peaks, _ = find_peaks(fx, prominence=0.4)
peak_coordinates = list(zip(peaks, fx[peaks]))

fig, ax = plt.subplots()
ax.plot(fx)
ax.plot(peaks, fx[peaks], "x")

y0,y1=ax.get_ylim()
ax.set_ylim(y0,y1*1.1) # fix top y-limit

for xp,yp in peak_coordinates:
    plt.text(xp*1.05, yp*1.05, xp, fontsize=10)

plt.show()

You can use Matplotlib text to add a string, or, in your particular case the x-axis values, to the Axes at location x (d in your example), y (e in your example) in data coordinates.

import matplotlib.pyplot as plt
from scipy.signal import find_peaks
import numpy as np

# curve setup
x = np.linspace(0,10*np.pi,200)
fx = np.sin(2*x)*np.cos(x/2)*np.exp(-0.1*x)

peaks, _ = find_peaks(fx, prominence=0.4)
peak_coordinates = list(zip(peaks, fx[peaks]))

fig, ax = plt.subplots()
ax.plot(fx)
ax.plot(peaks, fx[peaks], "x")

y0,y1=ax.get_ylim()
ax.set_ylim(y0,y1*1.1) # fix top y-limit

for xp,yp in peak_coordinates:
    plt.text(xp*1.05, yp*1.05, xp, fontsize=10)

plt.show()

peak_values

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文