.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_temporalTimeSeriesAnalysis/plot_autoregressiveExample.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_01_temporalTimeSeriesAnalysis_plot_autoregressiveExample.py: Generation of a autoregressive time series ========================================== .. GENERATED FROM PYTHON SOURCE LINES 7-9 Import requirements ------------------- .. GENERATED FROM PYTHON SOURCE LINES 9-14 .. code-block:: Python import os import numpy as np import plotly.graph_objects as go .. GENERATED FROM PYTHON SOURCE LINES 15-17 Define variables ---------------- .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python srate = 1 T = 500 sigma = 1.0 .. GENERATED FROM PYTHON SOURCE LINES 23-26 Create white noise ------------------ .. GENERATED FROM PYTHON SOURCE LINES 26-31 .. code-block:: Python time = np.arange(0, T, 1.0/srate) N = len(time) w = np.random.normal(loc=0, scale=sigma, size=N) .. GENERATED FROM PYTHON SOURCE LINES 32-35 Create autoregressive time series --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-41 .. code-block:: Python ar = np.empty(len(w), dtype=np.double) ar[0] = w[0] ar[1] = ar[0] + w[1] for i in range(2, len(w)): ar[i] = ar[i-1] - 0.9 * ar[i-2] + w[i] .. GENERATED FROM PYTHON SOURCE LINES 42-45 Plot autoregressive time series ------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 45-58 .. code-block:: Python fig = go.Figure() trace = go.Scatter(x=time, y=ar, mode="lines+markers") fig.add_trace(trace) fig.update_layout(xaxis=dict(title="Time (sec)"), yaxis=dict(title="x")) if not os.path.exists("figures"): os.mkdir("figures") fig.write_html("figures/autoregressive.html") fig.write_image("figures/autoregressive.png") fig .. raw:: html


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.119 seconds) .. _sphx_glr_download_auto_examples_01_temporalTimeSeriesAnalysis_plot_autoregressiveExample.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_autoregressiveExample.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_autoregressiveExample.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_autoregressiveExample.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_