[英]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在此處輸入圖像描述我想獲取文件並繪制正弦圖。 但是當我這樣做時,圖表會變得很奇怪。 我不知道該怎么辦。 幫我
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.