.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_sl_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_sl_method_delays.py: Compare Delays Across Different Source Localization Methods =========================================================== This example **visually compares the delays** observed for several common source localization techniques: - *MNE* - *Minimum Norm Estimate* - *dSPM* - *Dynamic Statistical Parametric Mapping* - *eLORETA* - *Exact Low-Resolution Electromagnetic Tomography* - *sLORETA* - *Standardized Low-Resolution Electromagnetic Tomography* - *LCMV* - *Linearly Constrained Minimum Variance beamformer* .. GENERATED FROM PYTHON SOURCE LINES 16-17 Now let's load data and visualize each method's delay. .. GENERATED FROM PYTHON SOURCE LINES 17-25 .. 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" / "SL_method_delays.csv" df = pd.read_csv(fname, index_col=0) .. GENERATED FROM PYTHON SOURCE LINES 26-27 Helper function for labeling each row .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. 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 33-34 Function to plot KDEs for a list of methods .. GENERATED FROM PYTHON SOURCE LINES 34-79 .. 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=-.05, light=.6) g = sns.FacetGrid( df_sub, row="method", hue="method", aspect=14, height=1, 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 ($s$)") g.despine(bottom=True, left=True) return g .. GENERATED FROM PYTHON SOURCE LINES 80-81 Next, visualize delays for "dSPM", "MNE", "sLORETA", "LCMV" .. GENERATED FROM PYTHON SOURCE LINES 81-89 .. code-block:: Python plot_method_delays( df, ["dSPM", "MNE", "sLORETA", "LCMV"], xlim=[0, 0.15], ylim=[0, 250] ) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_sl_method_delays_001.png :alt: plot sl method delays :srcset: /auto_examples/images/sphx_glr_plot_sl_method_delays_001.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 90-91 Next, visualize delays for "eLORETA" .. GENERATED FROM PYTHON SOURCE LINES 91-97 .. code-block:: Python plot_method_delays( df, ["eLORETA"], xlim=[0.7, 1.1], ylim=[0, 40] ) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_sl_method_delays_002.png :alt: plot sl method delays :srcset: /auto_examples/images/sphx_glr_plot_sl_method_delays_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.556 seconds) .. _sphx_glr_download_auto_examples_plot_sl_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_sl_method_delays.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sl_method_delays.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sl_method_delays.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_