<p>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.</p>
<p>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, <span class="math-container">$d^{-1}$</span>.</p>
<p>If your sampling rate is once per day, then you are getting no reliable information at all about frequencies <span class="math-container">$&gt;1$</span> d<span class="math-container">$^{-1}$</span>. The stuff you should be concentrating on lies between <span class="math-container">$0\leq f &lt; 1$</span> d<span class="math-container">$^{-1}$</span>. Even in this range you won't have good fidelity on signals with <span class="math-container">$0.5&lt;f&lt;1$</span> d<span class="math-container">$^{-1}$</span> because they are undersampled. You can also expect to get aliasing signals in the range <span class="math-container">$0\leq f &lt;1$</span> that are caused by true signals (including those with higher frequencies) aliasing with the 1 d<span class="math-container">$^{-1}$</span> frequency of your sampling.</p>
<p>It looks to me, by eye, like you might have a genuine signal at <span class="math-container">$1/7$</span> d<span class="math-container">$^{-1}$</span>, 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.</p>
<p>I would highly recommend reading <a href="https://iopscience.iop.org/article/10.3847/1538-4365/aab766" rel="nofollow noreferrer">VanderPlas 2018</a> for a thorough discussion of the Lomb-Scargle periodogram and its interpretation.</p>

CC BY-SA 4.0
2021-02-03T13:31:48.150Z
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?
rilesdg3
CC BY-SA 4.0
2021-02-03T18:09:07.960Z
Yes, you need to sample at better than twice the frequencies you are interested in. @rilesdg3
ProfRob
CC BY-SA 4.0
2021-02-03T12:58:18.017Z
2021-02-03T12:58:18.017Z
ProfRob
<p>lomb scargle periodogram:</p>
<p><img src="https://i.sstatic.net/ak8W2.png" alt="" /></p>
<pre><code>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')
m5_data.head()

     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

&quot;&quot;&quot;Converting dates to MJD &quot;&quot;&quot;
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()
plt.plot(m5_frequency,m5_power)
plt.show()
</code></pre>
<ol>
<li>What does the x axis represent? Is it frequencies in days or is it frequencies in 1/day?</li>
<li>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.</li>
</ol>
<p>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)</p>
<p>So the spike at 2 does not make sense to me.</p>

CC BY-SA 4.0
2021-02-02T20:52:46.890Z
Maybe programming Stack Exchange?
User123
CC BY-SA 4.0
2021-02-03T00:00:27.963Z
@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.
uhoh
CC BY-SA 4.0
2021-02-03T00:53:04.780Z
How can a frequency be measured in days?
ProfRob
CC BY-SA 4.0
2021-02-03T11:49:13.373Z
@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](https://github.com/jakevdp/PracticalLombScargle/tree/master/figures) and [here](https://arxiv.org/abs/1703.09824) and [here](https://astronomy.stackexchange.com/questions/29956/making-sense-of-the-lomb-scargle-periodogram?rq=1) 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)
rilesdg3
CC BY-SA 4.0
2021-02-03T14:46:19.303Z
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.
rilesdg3
<astrophysics><python><astropy>
How to Interpret Lomb Scargle periodogram
rilesdg3
# How to Interpret Lomb Scargle periodogram

(Asked by: username_0 on 2021-02-02)

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')
m5_data.head()

     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()
plt.plot(m5_frequency,m5_power)
plt.show()


What does the x axis represent? Is it frequencies in days or is it frequencies in 1/day?
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.

**Tags:** astrophysics, python, astropy
> **Comments:**
> **username_1**: Maybe programming Stack Exchange?  
> **username_2**: @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.  
> **username_3**: How can a frequency be measured in days?  
> **username_0**: @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](https://github.com/jakevdp/PracticalLombScargle/tree/master/figures) and [here](https://arxiv.org/abs/1703.09824) and [here](https://astronomy.stackexchange.com/questions/29956/making-sense-of-the-lomb-scargle-periodogram?rq=1) 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)  
> **username_0**: 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.  

---

## 1 answers

### Answer by username_3 on 2021-02-03. Score: 1 | Accepted answer

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 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](https://iopscience.iop.org/article/10.3847/1538-4365/aab766) for a thorough discussion of the Lomb-Scargle periodogram and its interpretation.

> **Comments:**
> **username_0**: 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?  
> **username_3**: Yes, you need to sample at better than twice the frequencies you are interested in. @rilesdg3  

---

