.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_scipy_auto_examples_plot_detrend.py: =================== Detrending a signal =================== :func:`scipy.signal.detrend` removes a linear trend. Generate a random signal with a trend .. code-block:: python import numpy as np t = np.linspace(0, 5, 100) x = t + np.random.normal(size=100) Detrend .. code-block:: python from scipy import signal x_detrended = signal.detrend(x) Plot .. code-block:: python from matplotlib import pyplot as plt plt.figure(figsize=(5, 4)) plt.plot(t, x, label="x") plt.plot(t, x_detrended, label="x_detrended") plt.legend(loc='best') plt.show() .. image:: /intro/scipy/auto_examples/images/sphx_glr_plot_detrend_001.png :class: sphx-glr-single-img **Total running time of the script:** ( 0 minutes 0.168 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_plot_detrend.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_detrend.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_detrend.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_