.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/signals/plot_synthetic_gaps.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_signals_plot_synthetic_gaps.py: =============================== Inserting gaps in a time series =============================== We will generate a linear time series with a sampling frequency of 4 hours, from 1975/05/09 to 1975/05/20, and remove 35% of the data using three different methods: 1. Random: removes data points at random location 2. Single: create a single data gap 3. Multiple: create a given number of gaps at random locations and of random sizes .. GENERATED FROM PYTHON SOURCE LINES 15-52 .. image-sg:: /auto_examples/signals/images/sphx_glr_plot_synthetic_gaps_001.png :alt: Random gaps, Single gap, Four non-overlapping gaps with random sizes and locations :srcset: /auto_examples/signals/images/sphx_glr_plot_synthetic_gaps_001.png :class: sphx-glr-single-img .. code-block:: default import matplotlib.pyplot as plt import pandas as pd from indsl.signals.generator import insert_data_gaps, line start = pd.Timestamp("1975/05/09") end = pd.Timestamp("1975/05/20") line1 = line(start_date=start, end_date=end, slope=1, intercept=5, sample_freq=pd.Timedelta("4 h")) remove = 0.35 fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(9, 7)) # Random Gaps ax1.plot(line1, "-") ts_rnd_gaps = insert_data_gaps(data=line1, fraction=remove, method="Random") ax1.plot(ts_rnd_gaps, "bo", mec="b", markerfacecolor="None", markersize=4) # Single gap ts_1_gap = insert_data_gaps(data=line1, fraction=remove, method="Single") ax2.plot(line1, "-") ax2.plot(ts_1_gap, "bo", mec="b", markerfacecolor="None", markersize=4) # Multiple gaps ts_mult_gaps = insert_data_gaps(data=line1, fraction=remove, method="Multiple", num_gaps=4) ax3.plot(line1, "-") ax3.plot(ts_mult_gaps, "bo", mec="b", markerfacecolor="None", markersize=4) ax1.set_title("Random gaps") ax2.set_title("Single gap") ax3.set_title("Four non-overlapping gaps with random sizes and locations ") ax1.get_xaxis().set_visible(False) ax2.get_xaxis().set_visible(False) fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.186 seconds) .. _sphx_glr_download_auto_examples_signals_plot_synthetic_gaps.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_synthetic_gaps.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_synthetic_gaps.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_