|
12 | 12 | from eeg_positions import get_elec_coords, plot_coords
|
13 | 13 |
|
14 | 14 | # %%
|
15 |
| -# Get the electrode positions! |
16 |
| -# Let's start with the basic 10-20 system in 2 dimensions (``"x"`` and ``"y"``). |
| 15 | +# Let's start with the basic 10-20 system in two dimensions: |
17 | 16 |
|
18 | 17 | coords = get_elec_coords(
|
19 | 18 | system="1020",
|
20 | 19 | dim="2d",
|
21 | 20 | )
|
22 | 21 |
|
23 |
| -# `coords` is a pandas.DataFrame object |
| 22 | +# %% |
| 23 | +# This function returns a ``pandas.DataFrame`` object: |
| 24 | + |
24 | 25 | coords.head()
|
25 | 26 |
|
26 | 27 | # %%
|
27 | 28 | # Now let's plot these coordinates.
|
28 | 29 | # We can supply some style arguments to :func:`eeg_positions.plot_coords` to control
|
29 |
| -# the color of the scatter dots, and the text annotations. |
| 30 | +# the color of the electrodes and the text annotations. |
30 | 31 |
|
31 | 32 | fig, ax = plot_coords(
|
32 |
| - coords, scatter_kwargs=dict(color="green"), text_kwargs=dict(fontsize=10) |
| 33 | + coords, scatter_kwargs={"color": "g"}, text_kwargs={"fontsize": 10} |
33 | 34 | )
|
34 | 35 |
|
35 |
| -ax.axis("off") |
36 | 36 | fig
|
37 | 37 |
|
38 | 38 | # %%
|
39 |
| -# Notice in the above plot, that the "landmarks" are there: ``NAS``, ``LPA``, |
40 |
| -# and ``RPA``. We can drop these by passing the ``drop_landmarks=True`` to |
41 |
| -# :func:`get_elec_coords`. |
| 39 | +# Notice that the "landmarks" ``NAS``, ``LPA``, and ``RPA`` are included. We can drop |
| 40 | +# these by passing ``drop_landmarks=True`` to :func:`get_elec_coords`: |
42 | 41 |
|
43 | 42 | coords = get_elec_coords(
|
44 | 43 | system="1020",
|
45 | 44 | drop_landmarks=True,
|
46 | 45 | dim="2d",
|
47 | 46 | )
|
48 | 47 |
|
49 |
| - |
50 | 48 | fig, ax = plot_coords(
|
51 |
| - coords, scatter_kwargs=dict(color="green"), text_kwargs=dict(fontsize=10) |
| 49 | + coords, scatter_kwargs={"color": "g"}, text_kwargs={"fontsize": 10} |
52 | 50 | )
|
53 | 51 |
|
54 |
| -ax.axis("off") |
55 | 52 | fig
|
56 | 53 |
|
57 | 54 | # %%
|
58 |
| -# We can also plot in 3D. Let's pick a system with more electrodes now. |
| 55 | +# Often, we might have a list of electrode names that we would like to plot. For |
| 56 | +# example, let's assume we have the following 64 channel labels (based on the 10-05 |
| 57 | +# system): |
| 58 | + |
| 59 | +chans = """Fp1 AF7 AF3 F1 F3 F5 F7 Fp2 AF8 AF4 F2 F4 F6 F8 FT7 FC5 FC3 |
| 60 | +FC1 C1 C3 C5 T7 TP7 CP5 CP3 CP1 FT8 FC6 FC4 FC2 C2 C4 C6 T8 TP8 CP6 CP4 |
| 61 | +CP2 P1 P3 P5 P7 P9 PO7 PO3 O1 P2 P4 P6 P8 P10 PO8 PO4 O2 Iz Oz POz Pz |
| 62 | +Fz AFz Fpz CPz Cz FCz""".split() |
| 63 | + |
| 64 | +# %% |
| 65 | +# Many experiments aggregate electrodes into regions of interest (ROIs), which we could |
| 66 | +# visualize with different colors. Let's get their coordinates first: |
| 67 | + |
| 68 | +coords = get_elec_coords(elec_names=chans) |
| 69 | + |
| 70 | +# %% |
| 71 | +# Now we specifiy individual colors using the ``scatter_kwargs``` argument. We create a |
| 72 | +# list of 64 colors corresponding to our 64 coordinates (in the original order as |
| 73 | +# provided by ``chans``): |
| 74 | + |
| 75 | +colors = ( |
| 76 | + ["salmon"] * 14 |
| 77 | + + ["skyblue"] * 24 |
| 78 | + + ["violet"] * 16 |
| 79 | + + ["lightgreen"] * 7 |
| 80 | + + ["khaki"] * 3 |
| 81 | +) |
| 82 | + |
| 83 | +# sphinx_gallery_thumbnail_number = 3 |
| 84 | +fig, ax = plot_coords( |
| 85 | + coords, |
| 86 | + scatter_kwargs={ |
| 87 | + "s": 150, # electrode size |
| 88 | + "color": colors, |
| 89 | + "edgecolors": "black", # black electrode outline |
| 90 | + "linewidths": 0.5, # thin outline |
| 91 | + }, |
| 92 | + text_kwargs={ |
| 93 | + "ha": "center", # center electrode label horizontally |
| 94 | + "va": "center", # center electrode label vertically |
| 95 | + "fontsize": 5, # smaller font size |
| 96 | + }, |
| 97 | +) |
| 98 | + |
| 99 | +# %% |
| 100 | +# We can also plot in 3D. Let's pick a system with more electrodes now: |
59 | 101 |
|
60 | 102 | coords = get_elec_coords(
|
61 | 103 | system="1010",
|
62 | 104 | drop_landmarks=True,
|
63 | 105 | dim="3d",
|
64 | 106 | )
|
65 | 107 |
|
66 |
| - |
67 | 108 | fig, ax = plot_coords(coords, text_kwargs=dict(fontsize=7))
|
68 | 109 |
|
69 | 110 | fig
|
70 | 111 |
|
71 | 112 | # %%
|
72 | 113 | # When using these commands from an interactive Python session, try to set
|
73 |
| -# the Ipython magic `%matplotlib qt`, which will allow you to freely view the 3d |
74 |
| -# plot and rotate the camera. |
| 114 | +# the IPython magic ``%matplotlib`` or ``%matplotlib qt``, which will allow you to |
| 115 | +# freely view the 3D plot and rotate the camera. |
0 commit comments