.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_temporalTimeSeriesAnalysis/plot_randomWalkWithDriftExample.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_randomWalkWithDriftExample.py: Generation of a random walk with drift 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-24 .. code-block:: Python srate = 1 T = 200 # sec sigma = 1.0 delta0 = 0.0 delta1 = .2 .. GENERATED FROM PYTHON SOURCE LINES 25-28 Create white noise ------------------ .. GENERATED FROM PYTHON SOURCE LINES 28-34 .. code-block:: Python time = np.arange(0, T, 1.0/srate) N = len(time) w0 = np.random.normal(loc=0, scale=sigma, size=N) w1 = np.random.normal(loc=0, scale=sigma, size=N) .. GENERATED FROM PYTHON SOURCE LINES 35-38 Create random walk with noise time series ----------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 38-47 .. code-block:: Python rwWithDrift0 = np.empty(N, dtype=np.double) rwWithDrift1 = np.empty(N, dtype=np.double) rwWithDrift0[0] = 0.0 rwWithDrift1[0] = 0.0 for i in range(1, N): rwWithDrift0[i] = delta0 + rwWithDrift0[i-1] + w0[i] rwWithDrift1[i] = delta1 + rwWithDrift1[i-1] + w1[i] .. GENERATED FROM PYTHON SOURCE LINES 48-51 Plot random noise with drift time series ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 51-74 .. code-block:: Python fig = go.Figure() trace = go.Scatter(x=time, y=rwWithDrift0, mode="lines+markers", line=dict(color="blue"), name=r"$\delta=0.0$") fig.add_trace(trace) trace = go.Scatter(x=time, y=rwWithDrift1, mode="lines+markers", line=dict(color="black"), name=r"$\delta=0.2$") fig.add_trace(trace) trace = go.Scatter(x=[0, T], y=[0, 0], line=dict(color="blue", dash="dot"), mode="lines", showlegend=False) fig.add_trace(trace) trace = go.Scatter(x=[0, T], y=[0, delta1*T], line=dict(color="black", dash="dot"), mode="lines", showlegend=False) 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/randomWalkWithDrift.html") fig.write_image("figures/randomWalkWithDrift.png") fig .. raw:: html


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