.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/examples/general/plot_padding_extrapolate.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_generated_examples_general_plot_padding_extrapolate.py: Padding with 'extrapolate' mode ------------------------------- Since version 0.7.0 of pybaselines, a list/tuple of two separate values can be specified for `extrapolate_window`, giving more control over the padding. .. GENERATED FROM PYTHON SOURCE LINES 11-53 .. image-sg:: /generated/examples/general/images/sphx_glr_plot_padding_extrapolate_001.png :alt: plot padding extrapolate :srcset: /generated/examples/general/images/sphx_glr_plot_padding_extrapolate_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from pybaselines.utils import _check_scalar, gaussian, pad_edges num_points = 1000 pad_len = 100 x = np.linspace(0, 1000, num_points) # use an exponentially decaying line to get a large edge effect one # one side and a small edge effect on the other line = 5 * np.exp(-x / 200) + gaussian(x, 5, 900, 20) + gaussian(x, 5, 200, 20) noise = np.random.default_rng(0).normal(0, 0.1, num_points) y = line + noise _, ax = plt.subplots() patch = ax.plot(pad_edges(y, pad_len, mode='constant', constant_values=np.nan))[0] extrapolate_windows = (1, 100, [100, 40]) legend = [[patch], ['original']] for i, extrapolate_window in enumerate(extrapolate_windows, 1): padded_y = pad_edges(y, pad_len, extrapolate_window=extrapolate_window) # offset each plot to show differences padded_y += 5 * i patch = ax.plot(padded_y)[0] legend[0].append(patch) legend[1].append(f'extrapolate_window={extrapolate_window}') # show only the section used for extrapolation padded_y[:pad_len] = np.nan padded_y[-pad_len:] = np.nan windows = _check_scalar(extrapolate_window, 2, True)[0] padded_y[pad_len + windows[0]:-pad_len - windows[1]] = np.nan section_patch = ax.plot(padded_y, 'c.')[0] ax.set_ylim([None, 31]) legend[0].insert(1, section_patch) legend[1].insert(1, 'fit points') ax.legend(*legend) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.076 seconds) .. _sphx_glr_download_generated_examples_general_plot_padding_extrapolate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_padding_extrapolate.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_padding_extrapolate.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_padding_extrapolate.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_