.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_method_delays.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_plot_method_delays.py: Compare different neurofeedback method delays =================================================== This example shows how to visualize delays for different neurofeedback methods using Seaborn's FacetGrid and KDE plots. .. GENERATED FROM PYTHON SOURCE LINES 10-11 Now let's load data and visualize each method's delay. .. GENERATED FROM PYTHON SOURCE LINES 11-19 .. code-block:: Python from pathlib import Path import pandas as pd import matplotlib.pyplot as plt import seaborn as sns fname = Path.cwd().parent / "data" / "sample" / "method_delays.csv" df = pd.read_csv(fname, index_col=0) .. GENERATED FROM PYTHON SOURCE LINES 20-21 Helper function for labeling each row .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python def label(x, color, label): ax = plt.gca() ax.text(0.8, .2, label, fontweight="bold", fontstyle='italic', color=color, ha="left", va="center", transform=ax.transAxes) .. GENERATED FROM PYTHON SOURCE LINES 27-28 Function to plot KDEs for a list of methods .. GENERATED FROM PYTHON SOURCE LINES 28-73 .. code-block:: Python def plot_method_delays(df, method_names, xlim, ylim, bw_adjust=1, top=0.72): """ Plot KDEs of delays for specified neurofeedback methods. Parameters ---------- df : pandas.DataFrame Must contain columns 'method' and 'delay'. method_names : list of str Methods to plot. xlim : list of float X-axis limits. ylim : list of float Y-axis limits. bw_adjust : float, optional Bandwidth adjustment for KDE (default 1). top : float, optional Top position for FacetGrid (default 0.72). Returns ------- g : seaborn.FacetGrid FacetGrid object. """ df_sub = df.query("method == @method_names") pal = sns.cubehelix_palette(len(method_names), rot=-.2, light=.7) g = sns.FacetGrid( df_sub, row="method", hue="method", aspect=14, height=.75, palette=pal, row_order=method_names, xlim=xlim, ylim=ylim ) g.map(sns.kdeplot, "delay", bw_adjust=bw_adjust, clip_on=False, clip=xlim, fill=True, alpha=1, linewidth=1.5) g.map(sns.kdeplot, "delay", clip_on=False, color="w", clip=xlim, lw=2, bw_adjust=bw_adjust) g.refline(y=0, linewidth=2, linestyle="-", color=None, clip_on=False) g.map(label, "delay") g.figure.subplots_adjust(hspace=.15, top=top) g.set_titles("") g.set(yticks=[], ylabel="", xlabel=r"method delay ($m s$)") g.despine(bottom=True, left=True) return g .. GENERATED FROM PYTHON SOURCE LINES 74-75 Now let's visualize delays for "sensor_power", "individual_peak_power", "band_ratio" .. GENERATED FROM PYTHON SOURCE LINES 75-83 .. code-block:: Python plot_method_delays( df, ["sensor_power", "individual_peak_power", "band_ratio"], xlim=[0, 0.2], ylim=[0, 50] ) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_method_delays_001.png :alt: plot method delays :srcset: /auto_examples/images/sphx_glr_plot_method_delays_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 84-85 Next, visualize delays for "entropy", "argmax_freq", "sensor_connectivity_corr" .. GENERATED FROM PYTHON SOURCE LINES 85-94 .. code-block:: Python plot_method_delays( df, ["entropy", "argmax_freq", "sensor_connectivity_corr"], xlim=[0.2, 1.8], ylim=[0, 6], bw_adjust=1.5 ) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_method_delays_002.png :alt: plot method delays :srcset: /auto_examples/images/sphx_glr_plot_method_delays_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 95-96 Next, visualize delays for "sensor_cfc", "sensor_connectivity_pli" .. GENERATED FROM PYTHON SOURCE LINES 96-106 .. code-block:: Python plot_method_delays( df, ["sensor_cfc", "sensor_connectivity_pli"], xlim=[-5, 30], ylim=[0, 0.2], bw_adjust=1.8, top=0.65 ) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_method_delays_003.png :alt: plot method delays :srcset: /auto_examples/images/sphx_glr_plot_method_delays_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /Users/payamsadeghishabestari/ANT/venv/lib/python3.10/site-packages/seaborn/axisgrid.py:123: UserWarning: Tight layout not applied. tight_layout cannot make Axes height small enough to accommodate all Axes decorations. self._figure.tight_layout(*args, **kwargs) /Users/payamsadeghishabestari/ANT/venv/lib/python3.10/site-packages/seaborn/axisgrid.py:123: UserWarning: Tight layout not applied. tight_layout cannot make Axes height small enough to accommodate all Axes decorations. self._figure.tight_layout(*args, **kwargs) /Users/payamsadeghishabestari/ANT/venv/lib/python3.10/site-packages/seaborn/axisgrid.py:123: UserWarning: Tight layout not applied. tight_layout cannot make Axes height small enough to accommodate all Axes decorations. self._figure.tight_layout(*args, **kwargs) /Users/payamsadeghishabestari/ANT/venv/lib/python3.10/site-packages/seaborn/axisgrid.py:123: UserWarning: Tight layout not applied. tight_layout cannot make Axes height small enough to accommodate all Axes decorations. self._figure.tight_layout(*args, **kwargs) .. GENERATED FROM PYTHON SOURCE LINES 107-108 Next, visualize delays for "sensor_graph_sqe", "sensor_graph_corr" .. GENERATED FROM PYTHON SOURCE LINES 108-116 .. code-block:: Python plot_method_delays( df, ["sensor_graph_sqe", "sensor_graph_corr"], xlim=[30, 80], ylim=[0, 0.1] ) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_method_delays_004.png :alt: plot method delays :srcset: /auto_examples/images/sphx_glr_plot_method_delays_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 117-118 Finally, visualize delays for "source_connectivity_pli", "source_connectivity_corr", "source_power", "source_graph" .. GENERATED FROM PYTHON SOURCE LINES 118-126 .. code-block:: Python plot_method_delays( df, ["source_connectivity_pli", "source_connectivity_corr", "source_power", "source_graph"], xlim=[0, 700], ylim=[0, 0.01], bw_adjust=1.5 ) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_method_delays_005.png :alt: plot method delays :srcset: /auto_examples/images/sphx_glr_plot_method_delays_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.089 seconds) .. _sphx_glr_download_auto_examples_plot_method_delays.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_method_delays.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_method_delays.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_method_delays.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_