I'm trying to compute the DFT using scipy's functions. I don't understand why the phase spectrum of a simple sine wave with 2 Hz frequency doesn't show $\pm\pi/2$ at the $\pm 2Hz$ frequencies. Instead, the phase plot seems to have some linear dependence in the frequency, which I don't understand. I provide the code for assistance. How can this be fixed? Looks like a simple issue I'm not grasping. Please help.
import numpy as np import matplotlib.pyplot as plt from scipy.fftpack import fft, fftfreq # 1Hz sine wave npts = 100 tmax = 10 t = np.linspace(0, tmax, npts) y = np.sin(2*np.pi*2*t) dt = tmax/npts # FFT computation Y = fft(y) freq = fftfreq(npts, d=dt) amplit = abs(Y)/npts phase = np.angle(Y) phase = phase / np.pi fig, ax = plt.subplots(1, 2, figsize=(10,4)) ax.plot(freq, amplit) ax.plot(freq, phase) ax.plot([2,2], [0,0.5], '--') ax.plot([-2,-2], [0,0.5], '--') ax.plot([2,2], [-1,1], '--') ax.plot([-2,-2], [-1,1], '--')