简体   繁体   中英

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. But when I do this, the graph comes out weird. I don't know what to do. Help me

You can use np.sin() to plot sine wave.

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()

The wave like that, and it can customized by you在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM