.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Plots/plot_events.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_Plots_plot_events.py: Plot events =========== .. GENERATED FROM PYTHON SOURCE LINES 7-19 .. code-block:: default import numpy as np import seaborn as sns from bokeh.io import output_notebook from bokeh.plotting import show from systole.detection import ecg_peaks from systole.plots import plot_events, plot_rr from systole import import_dataset1 # Author: Nicolas Legrand # Licence: GPL v3 .. GENERATED FROM PYTHON SOURCE LINES 20-22 Plot events distributions using Matplotlib as plotting backend -------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 22-36 .. code-block:: default ecg_df = import_dataset1(modalities=['ECG', "Stim"]) # Get events triggers triggers_idx = [ np.where(ecg_df.stim.to_numpy() == 2)[0], np.where(ecg_df.stim.to_numpy() == 1)[0] ] plot_events( triggers_idx=triggers_idx, labels=["Disgust", "Neutral"], tmin=-0.5, tmax=10.0, figsize=(13, 3), palette=[sns.xkcd_rgb["denim blue"], sns.xkcd_rgb["pale red"]], ) .. image-sg:: /auto_examples/Plots/images/sphx_glr_plot_events_001.png :alt: plot events :srcset: /auto_examples/Plots/images/sphx_glr_plot_events_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/2 [00:00 .. GENERATED FROM PYTHON SOURCE LINES 37-39 Plot events distributions using Bokeh as plotting backend and add the RR time series ------------------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 39-53 .. code-block:: default output_notebook() # Peak detection in the ECG signal using the Pan-Tompkins method signal, peaks = ecg_peaks(ecg_df.ecg, method='pan-tompkins', sfreq=1000) # First, we create a RR interval plot rr_plot = plot_rr(peaks, input_type='peaks', backend='bokeh', figsize=250) show( # Then we add events annotations to this plot using the plot_events function plot_events(triggers_idx=triggers_idx, backend="bokeh", labels=["Disgust", "Neutral"], tmin=-0.5, tmax=10.0, palette=[sns.xkcd_rgb["denim blue"], sns.xkcd_rgb["pale red"]], ax=rr_plot.children[0]) ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.838 seconds) .. _sphx_glr_download_auto_examples_Plots_plot_events.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_events.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_events.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_