Skip to content

Instantly share code, notes, and snippets.

@JustinSDK
Created May 17, 2021 02:43
Show Gist options
  • Save JustinSDK/c283a70cef65ec53deed3718ff180c5e to your computer and use it in GitHub Desktop.
Save JustinSDK/c283a70cef65ec53deed3718ff180c5e to your computer and use it in GitHub Desktop.
NumPy 與 Matplotlib 畫正弦波
import numpy as np
import matplotlib.pyplot as plt
freq = 10 # 頻率
stop = .25 # 取樣範圍為 0 ~ stop
sample_rate = 800 # 取樣率,單位 x 取樣幾次
x = np.linspace(0, stop, int(stop * sample_rate), endpoint = False)
y = np.sin(freq * 2 * np.pi * x)
plt.plot(x, y)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment