.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_positions.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_positions.py: ======================== Plot electrode positions ======================== .. currentmodule:: eeg_positions .. GENERATED FROM PYTHON SOURCE LINES 10-11 We need to import some functions. .. GENERATED FROM PYTHON SOURCE LINES 11-14 .. code-block:: Python from eeg_positions import get_elec_coords, plot_coords .. GENERATED FROM PYTHON SOURCE LINES 15-16 Let's start with the basic 10-20 system in two dimensions: .. GENERATED FROM PYTHON SOURCE LINES 16-22 .. code-block:: Python coords = get_elec_coords( system="1020", dim="2d", ) .. GENERATED FROM PYTHON SOURCE LINES 23-24 This function returns a ``pandas.DataFrame`` object: .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python coords.head() .. raw:: html
label x y
0 Cz 0.0 0.000000
1 Fpz 0.0 0.726585
2 Fz 0.0 0.324931
3 Pz 0.0 -0.324931
4 Oz 0.0 -0.726585


.. GENERATED FROM PYTHON SOURCE LINES 28-31 Now let's plot these coordinates. We can supply some style arguments to :func:`eeg_positions.plot_coords` to control the color of the electrodes and the text annotations. .. GENERATED FROM PYTHON SOURCE LINES 31-38 .. code-block:: Python fig, ax = plot_coords( coords, scatter_kwargs={"color": "g"}, text_kwargs={"fontsize": 10} ) fig .. image-sg:: /auto_examples/images/sphx_glr_plot_positions_001.png :alt: plot positions :srcset: /auto_examples/images/sphx_glr_plot_positions_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 39-41 Notice that the "landmarks" ``NAS``, ``LPA``, and ``RPA`` are included. We can drop these by passing ``drop_landmarks=True`` to :func:`get_elec_coords`: .. GENERATED FROM PYTHON SOURCE LINES 41-54 .. code-block:: Python coords = get_elec_coords( system="1020", drop_landmarks=True, dim="2d", ) fig, ax = plot_coords( coords, scatter_kwargs={"color": "g"}, text_kwargs={"fontsize": 10} ) fig .. image-sg:: /auto_examples/images/sphx_glr_plot_positions_002.png :alt: plot positions :srcset: /auto_examples/images/sphx_glr_plot_positions_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 55-58 Often, we might have a list of electrode names that we would like to plot. For example, let's assume we have the following 64 channel labels (based on the 10-05 system): .. GENERATED FROM PYTHON SOURCE LINES 58-64 .. code-block:: Python chans = """Fp1 AF7 AF3 F1 F3 F5 F7 Fp2 AF8 AF4 F2 F4 F6 F8 FT7 FC5 FC3 FC1 C1 C3 C5 T7 TP7 CP5 CP3 CP1 FT8 FC6 FC4 FC2 C2 C4 C6 T8 TP8 CP6 CP4 CP2 P1 P3 P5 P7 P9 PO7 PO3 O1 P2 P4 P6 P8 P10 PO8 PO4 O2 Iz Oz POz Pz Fz AFz Fpz CPz Cz FCz""".split() .. GENERATED FROM PYTHON SOURCE LINES 65-67 Many experiments aggregate electrodes into regions of interest (ROIs), which we could visualize with different colors. Let's get their coordinates first: .. GENERATED FROM PYTHON SOURCE LINES 67-70 .. code-block:: Python coords = get_elec_coords(elec_names=chans) .. GENERATED FROM PYTHON SOURCE LINES 71-74 Now we specifiy individual colors using the ``scatter_kwargs``` argument. We create a list of 64 colors corresponding to our 64 coordinates (in the original order as provided by ``chans``): .. GENERATED FROM PYTHON SOURCE LINES 74-98 .. code-block:: Python colors = ( ["salmon"] * 14 + ["skyblue"] * 24 + ["violet"] * 16 + ["lightgreen"] * 7 + ["khaki"] * 3 ) fig, ax = plot_coords( coords, scatter_kwargs={ "s": 150, # electrode size "color": colors, "edgecolors": "black", # black electrode outline "linewidths": 0.5, # thin outline }, text_kwargs={ "ha": "center", # center electrode label horizontally "va": "center", # center electrode label vertically "fontsize": 5, # smaller font size }, ) .. image-sg:: /auto_examples/images/sphx_glr_plot_positions_003.png :alt: plot positions :srcset: /auto_examples/images/sphx_glr_plot_positions_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 100-101 We can also plot in 3D. Let's pick a system with more electrodes now: .. GENERATED FROM PYTHON SOURCE LINES 101-112 .. code-block:: Python coords = get_elec_coords( system="1010", drop_landmarks=True, dim="3d", ) fig, ax = plot_coords(coords, text_kwargs=dict(fontsize=7)) fig .. image-sg:: /auto_examples/images/sphx_glr_plot_positions_004.png :alt: plot positions :srcset: /auto_examples/images/sphx_glr_plot_positions_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 113-116 When using these commands from an interactive Python session, try to set the IPython magic ``%matplotlib`` or ``%matplotlib qt``, which will allow you to freely view the 3D plot and rotate the camera. .. _sphx_glr_download_auto_examples_plot_positions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_positions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_positions.py `