簡體   English   中英

Python如何獲取文件plot圖形正弦波?

[英]Python how to get file plot graph sine wave?

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

sr = 2000         
ts = 1 / sr       
file_name = 'C:/Users/Desktop/test_data/sample_003.csv'

def x_sine():
    sample = pd.read_csv(file_name)
    array = np.array(sample)
    where_are_NaNs = np.isnan(array)
    array[where_are_NaNs] = 0

    x = array[:, 1]
    y = array[:, 2]
    z = array[:, 3]
    t = np.arange(0, np.size(x)) * ts

    ax = np.sin(2 * np.pi * t * x / sr)

    f = plt.figure()
    plt.title('Sine Wave Test - x-axis' + '\n' + file_name.split('/')[-1])

    plt.plot(x, ax)
    plt.xlabel('Time')
    plt.ylabel('Amplitude = sin(time)')

    plt.show()

sample_003.csv在此處輸入圖像描述我想獲取文件並繪制正弦圖。 但是當我這樣做時,圖表會變得很奇怪。 我不知道該怎么辦。 幫我

您可以使用np.sin()到 plot 正弦波。

import numpy as np 
import matplotlib.pyplot as plt 

x = np.arange(-5,5,0.1)
y = np.sin(x)
plt.plot(x,y)
plt.show()

像這樣的波浪,它可以由你定制在此處輸入圖像描述

暫無
暫無

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

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