lomb scargle periodogram:

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from scipy import signal
from astropy.time import Time
from astropy.timeseries import LombScargle

m5_data = pd.read_csv('tmp')

     date    sales
0  2011-01-29  32631.0
1  2011-01-30  31749.0
2  2011-01-31  23783.0
3  2011-02-01  25412.0
4  2011-02-02  19146.0

"""Converting dates to MJD """
tmp_str = m5_data.iloc[:,0].astype(pd.StringDtype())
t_date = np.array(tmp_str.values,dtype = 'str')
t_date = Time(t_date, format='isot', scale='utc')
t_date.format = 'mjd'

y = m5_data.iloc[:,1]
m5_ls = LombScargle(t_date, y)
m5_frequency, m5_power = m5_ls.autopower()
  1. What does the x axis represent? Is it frequencies in days or is it frequencies in 1/day?
  2. So the spike at 2 does that mean there is a period of every two days or does it mean there is a period 1/2 days, which is a fractional day and I do not understand how I could get fractional days when I only have 1 observation per day.

The overall goal is to find if the data is periodic. Given this data is sales of a product from a store I would expect that if the data is periodic that the periods would be 7days(weekly), 30days(monthly), 182days(semi annually)

So the spike at 2 does not make sense to me.

  • $\begingroup$ Maybe programming Stack Exchange? $\endgroup$
    – User123
    Feb 2, 2021 at 20:52
  • $\begingroup$ @User123 the question is about an astronomical technique and is just fine here. Astronomers use computer programs as often as they use telescopes to learn about the universe. $\endgroup$
    – uhoh
    Feb 3, 2021 at 0:00
  • 1
    $\begingroup$ How can a frequency be measured in days? $\endgroup$
    – ProfRob
    Feb 3, 2021 at 0:53
  • $\begingroup$ @ProfRob The data is daily samples i.e. one sample/observation a day. I guess the frequency is not days, but the period would be days which is 1/frequency, is that correct? It is the period that I am looking for. Looking here and here and here it seems like they talk about days/hour only when they convert from frequency to period which is 1/freq or 24/freq(if sampled in minutes) $\endgroup$
    – rilesdg3
    Feb 3, 2021 at 11:49
  • $\begingroup$ Please don't edit this question all willy nilly, the data.head() is very important for people to get an idea of the exact type of data being used. $\endgroup$
    – rilesdg3
    Feb 3, 2021 at 14:46

1 Answer 1


The x-axis of a periodogram is usually a frequency, measured in inverse time units. It is possible to plot the inverse of frequency, in which case the axis would be non-linear.

In your case, the x-axis looks linear, and the the code you present appears to be using something labelled as a frequency on the x-axis. Therefore I would assume (though I would read the documentation for the functions you are using) that the x-axis is frequency. The units will be based on whatever units are in your input. i.e. It is just the inverse of whatever you are giving it for the times - in this case, $d^{-1}$.

If your sampling rate is once per day, then you are getting no reliable information at all about frequencies $>1$ d$^{-1}$. The stuff you should be concentrating on lies between $0\leq f < 1$ d$^{-1}$. Even in this range you won't have good fidelity on signals with $0.5<f<1$ d$^{-1}$ because they are undersampled. You can also expect to get aliasing signals in the range $0\leq f <1$ that are caused by true signals (including those with higher frequencies) aliasing with the 1 d$^{-1}$ frequency of your sampling.

It looks to me, by eye, like you might have a genuine signal at $1/7$ d$^{-1}$, corresponding to a weekly variation. There may be a weaker signal at much lower frequencies that might correspond to a monthly signal. The 2 signals either side of 1 day look like aliases of the weekly signal with the sampling frequency.

I would highly recommend reading VanderPlas 2018 for a thorough discussion of the Lomb-Scargle periodogram and its interpretation.

  • $\begingroup$ yes, frequency would be the x-axis. I get no reliable information about frequencies > 1d^-1 is that because there are no intr-aday times like minutes,seconds? $\endgroup$
    – rilesdg3
    Feb 3, 2021 at 13:31
  • $\begingroup$ Yes, you need to sample at better than twice the frequencies you are interested in. @rilesdg3 $\endgroup$
    – ProfRob
    Feb 3, 2021 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .