[英]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 enter image description here I want to get a file and draw a sine graph. sample_003.csv在此处输入图像描述我想获取文件并绘制正弦图。 But when I do this, the graph comes out weird.但是当我这样做时,图表会变得很奇怪。 I don't know what to do.我不知道该怎么办。 Help me帮我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.