【问题标题】:plot specific values on a plot在绘图上绘制特定值
【发布时间】:2021-10-09 12:29:20
【问题描述】:

我从 matplotlib 图中得到了这个图。

我的代码在这里显示:

from os import sep
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
from numpy.fft import rfft, rfftfreq



    
dt=1/10000
    
g=pd.read_csv('20210803-0002.csv', sep = ';', skiprows=[1,2],usecols = [4],dtype=float, decimal=',')
    
n=len(g)
   
acc=g.values.flatten() #to convert DataFrame to 1D array
    #acc value must be in numpy array format for half way mirror calculation

fft=rfft(acc)*dt
freq=rfftfreq(n,d=dt)

FFT=abs(fft)

plt.plot(freq,FFT,label = 'neuer Motor')

plt.legend()    


plt.show()
plt.close()

我想为每个 y 值 > 10 添加一个标记。

你们中有人知道如何在图表上绘制这些值吗?

【问题讨论】:

    标签: python pandas numpy matplotlib plot


    【解决方案1】:

    您可以设置阈值并使用它来创建过滤器:

    threshold = 40
    filt = y > threshold
    

    然后你可以过滤xy值:

    ax.plot(x, y)
    ax.plot(x[filt], y[filt], marker = 'o', linestyle = '')
    

    完整代码

    import numpy as np
    import matplotlib.pyplot as plt
    
    N = 1000
    x = np.linspace(0, 3000, N)
    y = 50*np.random.rand(N)
    
    
    threshold = 40
    filt = y > threshold
    
    
    fig, ax = plt.subplots()
    
    ax.plot(x, y)
    ax.plot(x[filt], y[filt], marker = 'o', linestyle = '')
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2012-11-05
      • 2014-11-02
      • 1970-01-01
      • 2019-04-09
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多