{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plot events\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport seaborn as sns\nfrom bokeh.io import output_notebook\nfrom bokeh.plotting import show\nfrom systole.detection import ecg_peaks\nfrom systole.plots import plot_events, plot_rr\n\nfrom systole import import_dataset1\n\n# Author: Nicolas Legrand \n# Licence: Apache-2.0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot events distributions using Matplotlib as plotting backend\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ecg_df = import_dataset1(modalities=['ECG', \"Stim\"])\n\n# Get events triggers\ntriggers_idx = [\n np.where(ecg_df.stim.to_numpy() == 2)[0],\n np.where(ecg_df.stim.to_numpy() == 1)[0]\n]\n\nplot_events(\n triggers_idx=triggers_idx, labels=[\"Disgust\", \"Neutral\"],\n tmin=-0.5, tmax=10.0, figsize=(13, 3),\n palette=[sns.xkcd_rgb[\"denim blue\"], sns.xkcd_rgb[\"pale red\"]],\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot events distributions using Bokeh as plotting backend and add the RR time series\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "output_notebook()\n\n# Peak detection in the ECG signal using the Pan-Tompkins method\nsignal, peaks = ecg_peaks(ecg_df.ecg, method='pan-tompkins', sfreq=1000)\n\n# First, we create a RR interval plot\nrr_plot = plot_rr(peaks, input_type='peaks', backend='bokeh', figsize=250)\n\nshow(\n # Then we add events annotations to this plot using the plot_events function\n plot_events(triggers_idx=triggers_idx, backend=\"bokeh\", labels=[\"Disgust\", \"Neutral\"],\n tmin=-0.5, tmax=10.0, palette=[sns.xkcd_rgb[\"denim blue\"], sns.xkcd_rgb[\"pale red\"]],\n ax=rr_plot.children[0])\n)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.16" } }, "nbformat": 4, "nbformat_minor": 0 }