# Problem : why autopower makes such terrible mistake ?
f0 = 1 / 6.0
t = np.linspace(0, 100, 10000)
y = np.sin(2.0 * np.pi *f0 * t )
# set grid
f_grid = np.linspace(0, 1, 1001)[1:]
P_true_grid = LombScargle(t, y, 1).power(f_grid)
# auto grid
f_auto, P_true_auto = LombScargle(t, y).autopower()
fig, ax= plt.subplots(3,1,figsize=(5,7))
ax[0].plot(f_grid, P_true_grid)
ax[0].text(0.96, 0.92, "True PSD, \nSet frequency grid", ha='right', va='top', transform=ax[0].transAxes)
ax[0].set_ylim(-0.1, 1.1)
ax[0].set_xlabel('$f$')
ax[0].set_ylabel(r'$P_{\rm LS}(f)$')
ax[0].axvline(f0, ls='--', c='red', lw=2)
ax[1].plot(f_auto, P_true_auto)
ax[1].text(0.96, 0.92, "True PSD, \nAuto frequency grid", ha='right', va='top', transform=ax[1].transAxes)
ax[1].set_ylim(-0.1, 1.1)
ax[1].set_xlim(-0.4,)
ax[1].set_xlabel('$f$')
ax[1].set_ylabel(r'$P_{\rm LS}(f)$')
ax[1].axvline(f0, ls='--', c='red', lw=2)
ax[2].scatter(t, y, c='gray', lw=0, s=1, alpha=0.6)
ax[2].text(0.96, 0.92, "Data", ha='right', va='top', transform=ax[2].transAxes)
ax[2].set_ylim(-1.5, 1.8)
ax[2].set_xlabel('$t$')
ax[2].set_ylabel('$y(t)$')
ax[2].set_ylim(-1.5, 1.8)