Repository navigation
Expand file tree
/
Copy pathplots.py
More file actions
1817 lines (1565 loc) · 59.4 KB
/
Copy pathplots.py
File metadata and controls
1817 lines (1565 loc) · 59.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Plot generation utilities for the Neuro-Urbanism corpus analysis."""
import csv
import re
from io import StringIO
from pathlib import Path
import matplotlib as mpl
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.collections import LineCollection
from scipy import stats
# Replicability labels used by reporting-rate plots.
NECESSARY_COLS: dict[str, str] = {
"SR_in_Hz": "Sample rate",
"online_filters": "Online filters applied",
"num_channels": "Number of channels",
"electrode_type": "Electrode type",
"electrode_locations": "Electrode locations",
"reference": "Reference scheme",
"artifact_rejection": "Artifact rejection",
}
mpl.rcParams["svg.fonttype"] = "path"
mpl.rcParams["pdf.fonttype"] = 42
mpl.rcParams["ps.fonttype"] = 42
EXPORT_DIR = Path("exports")
EXPORT_DIR.mkdir(exist_ok=True)
FONT_STACK = [
"Neue Haas Grotesk Text Pro",
"Neue Haas Grotesk Display Pro",
"Neue Haas Grotesk",
"Avenir Next",
"Helvetica Neue",
"Futura",
"DejaVu Sans",
]
def export_figure(fig: plt.Figure, stem: str) -> None:
"""Export a figure in SVG, PDF, and EPS formats."""
fig.savefig(
EXPORT_DIR / f"{stem}.svg", format="svg", bbox_inches="tight", facecolor="white"
)
# fig.savefig(EXPORT_DIR / f"{stem}.pdf", format="pdf", bbox_inches="tight", facecolor="white")
# fig.savefig(EXPORT_DIR / f"{stem}.eps", format="eps", bbox_inches="tight", facecolor="white")
fig.savefig(
EXPORT_DIR / f"{stem}.png", format="png", bbox_inches="tight", facecolor="white"
)
print(f" Saved plot: {stem}")
def split_values(text: object) -> list[str]:
if pd.isna(text):
return []
row = next(csv.reader(StringIO(str(text)), skipinitialspace=True))
return [item.strip().strip('"').strip("'").strip() for item in row if item.strip()]
def set_plot_style() -> None:
plt.rcParams.update(
{
"font.family": "sans-serif",
"mathtext.fontset": "stix",
"font.sans-serif": FONT_STACK,
"axes.titlesize": 11,
"axes.labelsize": 9,
"xtick.labelsize": 8,
"ytick.labelsize": 8,
"legend.fontsize": 8,
}
)
def plot_research_topic(df: pd.DataFrame) -> None:
broad_values = []
for raw in df["Research Topic"].dropna():
broad_values.extend(split_values(raw))
broad_counts = pd.Series(broad_values).value_counts()
bar_total = broad_counts.sum()
set_plot_style()
viridis = plt.get_cmap("viridis")
family_palette = {
"nature": "#4C9A74",
"architectural": viridis(0.18),
"urban": viridis(0.42),
"ambient": viridis(0.68),
"methods": viridis(0.90),
"other": "#7C817A",
}
category_color_map = {
"Nature & restorative environments": family_palette["nature"],
"Architectural & built interior spaces": family_palette["architectural"],
"Urban outdoor environments": family_palette["urban"],
"Multisensory & environmental stimuli": family_palette["ambient"],
"Methods & technology": family_palette["methods"],
}
def color_for_category(cat: str):
return category_color_map.get(cat, family_palette["other"])
pie_counts = broad_counts
pie_colors = [color_for_category(cat) for cat in pie_counts.index]
fig1, ax1 = plt.subplots(figsize=(6.8, 4.8), dpi=300)
wedges, texts, autotexts = ax1.pie(
pie_counts.values,
labels=pie_counts.index,
colors=pie_colors,
startangle=105,
autopct=lambda p: f"{p:.1f}%" if p >= 4 else "",
pctdistance=0.78,
labeldistance=1.04,
wedgeprops={"linewidth": 0.8, "edgecolor": "white"},
textprops={"color": "#2A2A2A", "fontsize": 5.5},
)
for wedge, t in zip(wedges, autotexts):
r, g, b, _ = wedge.get_facecolor()
luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
t.set_color("white" if luminance < 0.52 else "#3A3A3A")
t.set_fontsize(5.5)
ax1.set_title("Research Object Distribution", loc="left", pad=8, color="#1F1F1F")
plt.tight_layout()
export_figure(fig1, "research_object_distribution")
plt.close(fig1)
bar_counts = broad_counts.sort_values()
bar_colors = [color_for_category(cat) for cat in bar_counts.index]
fig2, ax2 = plt.subplots(figsize=(7.0, 4.9), dpi=300)
bars = ax2.barh(bar_counts.index, bar_counts.values, color=bar_colors, height=0.62)
ax2.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax2.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax2.spines[spine].set_visible(False)
ax2.set_title(
"Environmental Focus Distribution", pad=8, loc="left", color="#1F1F1F"
)
ax2.set_xlabel("Number of Papers", color="#3A3A3A", labelpad=6)
ax2.set_ylabel("")
ax2.tick_params(axis="x", colors="#555555", length=0)
ax2.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
for bar in bars:
width = bar.get_width()
pct = width / bar_total * 100
ax2.text(
width + max(bar_counts.values) * 0.01,
bar.get_y() + bar.get_height() / 2,
f"{pct:.1f}%",
va="center",
ha="left",
fontsize=8,
color="#4A4A4A",
)
legend_handles = [
mpatches.Patch(color=family_palette["nature"], label="Nature"),
mpatches.Patch(color=family_palette["architectural"], label="Architectural"),
mpatches.Patch(color=family_palette["urban"], label="Urban"),
mpatches.Patch(color=family_palette["ambient"], label="Multisensory/Ambient"),
mpatches.Patch(color=family_palette["methods"], label="Methods"),
]
ax2.legend(
handles=legend_handles,
frameon=False,
loc="lower right",
fontsize=8,
labelcolor="#4A4A4A",
)
fig2.tight_layout()
export_figure(fig2, "fig3b_research_topic_distribution")
plt.close(fig2)
def plot_motivation(df: pd.DataFrame) -> None:
motivation_values = []
for raw in df["Motivation"].dropna():
motivation_values.extend(split_values(raw))
motivation_counts = pd.Series(motivation_values).value_counts()
set_plot_style()
palette = [
"#16324F",
"#1D5F7A",
"#2A9D8F",
"#4CC9A6",
"#6ED8B5",
"#A8E6CF",
"#D4F1EF",
"#8AC6E8",
"#5E8CA8",
"#C8DDE8",
]
pie_counts = motivation_counts
pie_colors = [palette[i % len(palette)] for i in range(len(pie_counts))]
fig, ax = plt.subplots(figsize=(6.8, 4.8), dpi=300)
wedges, texts, autotexts = ax.pie(
pie_counts.values,
labels=pie_counts.index,
colors=pie_colors,
startangle=105,
autopct=lambda p: f"{p:.1f}%" if p >= 4 else "",
pctdistance=0.78,
labeldistance=1.04,
wedgeprops={"linewidth": 0.8, "edgecolor": "white"},
textprops={"color": "#2A2A2A", "fontsize": 8},
)
for wedge, t in zip(wedges, autotexts):
r, g, b, _ = wedge.get_facecolor()
luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
t.set_color("white" if luminance < 0.55 else "#1F1F1F")
t.set_fontsize(8)
ax.set_title("Motivation Distribution", loc="left", pad=8, color="#1F1F1F")
plt.tight_layout()
export_figure(fig, "motivation_distribution")
plt.close(fig)
def plot_study_design(df: pd.DataFrame) -> None:
total = len(df)
design_counts = pd.Series(
{
"Lab (incl. HMD/VR)": df["lab_realworld_binary"].eq(1).sum(),
"Real-world (mobile)": df["lab_realworld_binary"].eq(2).sum(),
"Combined lab+field": df["lab_realworld_binary"].eq(3).sum(),
}
)
if design_counts.sum() == 0:
print(" No study design data found; skipping study_design plot.")
return
set_plot_style()
palette = ["#0B3C5D", "#2A9D8F", "#A8E6CF"]
fig, ax = plt.subplots(figsize=(6.8, 4.8), dpi=300)
wedges, texts, autotexts = ax.pie(
design_counts.values,
labels=design_counts.index,
colors=palette,
startangle=105,
autopct=lambda p: f"{p:.1f}%" if p >= 4 else "",
pctdistance=0.78,
labeldistance=1.04,
wedgeprops={"linewidth": 0.8, "edgecolor": "white"},
textprops={"color": "#2A2A2A", "fontsize": 8},
)
for wedge, t in zip(wedges, autotexts):
r, g, b, _ = wedge.get_facecolor()
luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
t.set_color("white" if luminance < 0.55 else "#1F1F1F")
t.set_fontsize(8)
ax.set_title("Study Design Distribution", loc="left", pad=8, color="#1F1F1F")
ax.text(
0.5,
-0.08,
f"N = {total}",
transform=ax.transAxes,
ha="center",
va="top",
fontsize=8,
color="#555555",
)
plt.tight_layout()
export_figure(fig, "fig3a_study_design_distribution")
plt.close(fig)
def plot_paradigm_by_research_object(df: pd.DataFrame) -> None:
topic_labels = [
"Nature & restorative environments",
"Architectural & built interior spaces",
"Urban outdoor environments",
"Multisensory & environmental stimuli",
"Methods & technology",
]
rows = []
for _, row in df.iterrows():
raw_topics = split_values(row.get("Research Topic"))
mapped_topics = [topic for topic in raw_topics if topic in topic_labels]
if not mapped_topics:
continue
mobility = str(row.get("EEG_system_mobile_stationary", "")).strip().lower()
for topic in mapped_topics:
rows.append({"topic": topic, "mobility": mobility})
if not rows:
print(
" No research-object paradigm data found; skipping paradigm_by_research_object plot."
)
return
topic_frame = pd.DataFrame(rows)
summary = topic_frame.groupby("topic", sort=False).agg(
total=("mobility", "size"),
stationary=("mobility", lambda s: s.eq("stat").sum()),
hmd=("mobility", lambda s: s.eq("stat - hmd").sum()),
mobile=("mobility", lambda s: s.str.contains("mobile", na=False).sum()),
)
summary = summary.reindex(
[topic for topic in topic_labels if topic in summary.index]
)
summary = summary.dropna(subset=["total"])
if summary.empty:
print(
" No research-object paradigm data found; skipping paradigm_by_research_object plot."
)
return
count_table = pd.DataFrame(
{
"Stationary lab": summary["stationary"],
"HMD/VR": summary["hmd"],
"Mobile": summary["mobile"],
}
)
count_table["Other/NA"] = (
summary["total"] - (summary["stationary"] + summary["hmd"] + summary["mobile"])
).clip(lower=0)
set_plot_style()
colors = {
"Stationary lab": "#0B3C5D",
"HMD/VR": "#2A9D8F",
"Mobile": "#A8E6CF",
"Other/NA": "#D7DEE3",
}
fig, ax = plt.subplots(figsize=(8.0, 5.0), dpi=300)
left = np.zeros(len(count_table))
y_labels = count_table.index.tolist()
totals = summary["total"].to_numpy()
for column in ["Stationary lab", "HMD/VR", "Mobile", "Other/NA"]:
values = count_table[column].to_numpy()
bars = ax.barh(
y_labels, values, left=left, color=colors[column], height=0.62, label=column
)
for bar, value, total in zip(bars, values, totals):
pct_value = (value / total * 100) if total > 0 else 0
if pct_value >= 9:
ax.text(
bar.get_x() + bar.get_width() / 2,
bar.get_y() + bar.get_height() / 2,
f"{pct_value:.1f}%",
ha="center",
va="center",
fontsize=8,
color="white"
if column in {"Stationary lab", "HMD/VR"}
else "#1F1F1F",
)
left += values
ax.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax.spines[spine].set_visible(False)
ax.set_title(
"Paradigm Choice by Research Object", loc="left", pad=8, color="#1F1F1F"
)
ax.set_xlabel("Number of studies", color="#3A3A3A", labelpad=6)
ax.set_ylabel("")
max_total = int(summary["total"].max())
ax.set_xlim(0, max_total * 1.12)
ax.tick_params(axis="x", colors="#555555", length=0)
ax.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
for i, (topic, total) in enumerate(summary["total"].items()):
ax.text(
total + max_total * 0.01,
i,
f"n={int(total)}",
va="center",
ha="left",
fontsize=8,
color="#555555",
)
ax.legend(frameon=False, loc="lower right", ncol=2)
fig.tight_layout()
export_figure(fig, "fig3c_paradigm_by_research_object")
plt.close(fig)
def plot_study_design_by_research_object(df: pd.DataFrame) -> None:
topic_labels = [
"Nature & restorative environments",
"Architectural & built interior spaces",
"Urban outdoor environments",
"Multisensory & environmental stimuli",
"Methods & technology",
]
design_map = {
1: "Lab",
2: "Real-world",
3: "Combined lab+field",
}
rows = []
for _, row in df.iterrows():
raw_topics = split_values(row.get("Research Topic"))
mapped_topics = [topic for topic in raw_topics if topic in topic_labels]
if not mapped_topics:
continue
design_code = pd.to_numeric(row.get("lab_realworld_binary"), errors="coerce")
if pd.notna(design_code):
design_label = design_map.get(int(design_code), "Other/NA")
else:
design_label = "Other/NA"
for topic in mapped_topics:
rows.append({"topic": topic, "design": design_label})
if not rows:
print(
" No research-object study-design data found; skipping study_design_by_research_object plot."
)
return
topic_frame = pd.DataFrame(rows)
summary = topic_frame.groupby("topic", sort=False).agg(
total=("design", "size"),
lab=("design", lambda s: s.eq("Lab").sum()),
real_world=("design", lambda s: s.eq("Real-world").sum()),
combined=("design", lambda s: s.eq("Combined lab+field").sum()),
)
summary = summary.reindex(
[topic for topic in topic_labels if topic in summary.index]
)
summary = summary.dropna(subset=["total"])
if summary.empty:
print(
" No research-object study-design data found; skipping study_design_by_research_object plot."
)
return
count_table = pd.DataFrame(
{
"Lab": summary["lab"],
"Real-world": summary["real_world"],
"Combined lab+field": summary["combined"],
}
)
count_table["Other/NA"] = (
summary["total"]
- (summary["lab"] + summary["real_world"] + summary["combined"])
).clip(lower=0)
set_plot_style()
colors = {
"Lab": "#0B3C5D",
"Real-world": "#2A9D8F",
"Combined lab+field": "#A8E6CF",
"Other/NA": "#D7DEE3",
}
fig, ax = plt.subplots(figsize=(8.0, 5.0), dpi=300)
left = np.zeros(len(count_table))
y_labels = count_table.index.tolist()
totals = summary["total"].to_numpy()
for column in ["Lab", "Real-world", "Combined lab+field", "Other/NA"]:
values = count_table[column].to_numpy()
bars = ax.barh(
y_labels, values, left=left, color=colors[column], height=0.62, label=column
)
for bar, value, total in zip(bars, values, totals):
pct_value = (value / total * 100) if total > 0 else 0
if pct_value >= 9:
ax.text(
bar.get_x() + bar.get_width() / 2,
bar.get_y() + bar.get_height() / 2,
f"{pct_value:.1f}%",
ha="center",
va="center",
fontsize=8,
color="white" if column in {"Lab", "Real-world"} else "#1F1F1F",
)
left += values
ax.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax.spines[spine].set_visible(False)
ax.set_title("Study Design by Research Object", loc="left", pad=8, color="#1F1F1F")
ax.set_xlabel("Number of studies", color="#3A3A3A", labelpad=6)
ax.set_ylabel("")
max_total = int(summary["total"].max())
ax.set_xlim(0, max_total * 1.12)
ax.tick_params(axis="x", colors="#555555", length=0)
ax.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
for i, (topic, total) in enumerate(summary["total"].items()):
ax.text(
total + max_total * 0.01,
i,
f"n={int(total)}",
va="center",
ha="left",
fontsize=8,
color="#555555",
)
ax.legend(frameon=False, loc="lower right", ncol=2)
fig.tight_layout()
export_figure(fig, "study_design_by_research_object")
plt.close(fig)
def plot_non_replicability_by_topic(df: pd.DataFrame) -> None:
topic_labels = {
"Nature & restorative environments",
"Architectural & built interior spaces",
"Urban outdoor environments",
"Multisensory & environmental stimuli",
"Methods & technology",
}
topic_rows = []
for _, row in df.iterrows():
raw_topics = split_values(row.get("Research Topic"))
mapped_topics = [topic for topic in raw_topics if topic in topic_labels]
if not mapped_topics:
continue
for topic in mapped_topics:
topic_rows.append(
{
"topic": topic,
"replicable": bool(row.get("replicable", False)),
}
)
if not topic_rows:
print(
" No research topic data found; skipping non_replicability_by_topic plot."
)
return
topic_frame = pd.DataFrame(topic_rows)
summary = topic_frame.groupby("topic", sort=False).agg(
total=("replicable", "size"),
non_replicable=("replicable", lambda s: (~s).sum()),
)
summary["non_replicability_pct"] = (
summary["non_replicable"] / summary["total"] * 100
)
summary = summary.sort_values("non_replicability_pct", ascending=True)
set_plot_style()
fig, ax = plt.subplots(figsize=(7.2, 4.8), dpi=300)
bars = ax.barh(
summary.index, summary["non_replicability_pct"], color="#0B3C5D", height=0.62
)
ax.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax.spines[spine].set_visible(False)
ax.set_title(
"Non-replicability by Research Topic", loc="left", pad=8, color="#1F1F1F"
)
ax.set_xlabel("Non-replicable share (%)", color="#3A3A3A", labelpad=6)
ax.set_ylabel("")
ax.tick_params(axis="x", colors="#555555", length=0)
ax.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
max_pct = (
float(summary["non_replicability_pct"].max()) if not summary.empty else 0.0
)
for bar, (_, row) in zip(bars, summary.iterrows()):
ax.text(
bar.get_width() + max_pct * 0.015,
bar.get_y() + bar.get_height() / 2,
f"{row['non_replicability_pct']:.1f}%",
va="center",
ha="left",
fontsize=8,
color="#4A4A4A",
)
fig.tight_layout()
export_figure(fig, "fig7c_non_replicability_by_topic")
plt.close(fig)
def plot_analytic_domain(df: pd.DataFrame) -> None:
total = len(df)
domain_counts = pd.Series(
{
"Frequency domain": df["EEG_features_cat"]
.astype(str)
.str.contains(r"\b2\b", regex=True, na=False)
.sum(),
"Time domain (ERP)": df["EEG_features_cat"]
.astype(str)
.str.contains(r"\b1\b", regex=True, na=False)
.sum(),
"Functional connectivity": df["EEG_features_cat"]
.astype(str)
.str.contains(r"\b3\b", regex=True, na=False)
.sum(),
"Source localisation": df["EEG_features_cat"]
.astype(str)
.str.contains(r"\b4\b", regex=True, na=False)
.sum(),
"Proprietary output": df["EEG_features_cat"]
.astype(str)
.str.contains(r"(?:9|propriat)", regex=True, na=False)
.sum(),
}
).sort_values(ascending=True)
if domain_counts.sum() == 0:
print(" No EEG feature data found; skipping analytic_domain plot.")
return
set_plot_style()
palette = {
"Frequency domain": "#0B3C5D",
"Time domain (ERP)": "#2A9D8F",
"Functional connectivity": "#4CC9A6",
"Source localisation": "#6BA8B8",
"Proprietary output": "#A8E6CF",
}
fig, ax = plt.subplots(figsize=(7.2, 4.8), dpi=300)
bars = ax.barh(
domain_counts.index,
domain_counts.values,
color=[palette[k] for k in domain_counts.index],
height=0.62,
)
ax.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax.spines[spine].set_visible(False)
ax.set_title("Analytic Domain Distribution", loc="left", pad=8, color="#1F1F1F")
ax.set_xlabel("Number of papers", color="#3A3A3A", labelpad=6)
ax.set_ylabel("")
ax.tick_params(axis="x", colors="#555555", length=0)
ax.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
max_count = int(domain_counts.max()) if not domain_counts.empty else 0
for bar, count in zip(bars, domain_counts.values):
ax.text(
bar.get_width() + max_count * 0.015,
bar.get_y() + bar.get_height() / 2,
f"{count / total * 100:.1f}%",
va="center",
ha="left",
fontsize=8,
color="#4A4A4A",
)
fig.tight_layout()
export_figure(fig, "fig4a_analytic_domain_distribution")
plt.close(fig)
def plot_frequency_bands(df: pd.DataFrame) -> None:
freq_mask = (
df["EEG_features_cat"].astype(str).str.contains(r"\b2\b", regex=True, na=False)
)
ps_freq = df.loc[freq_mask, "EEG_parameter_space"].astype(str)
freq_total = len(ps_freq)
band_patterns = [
("Alpha", r"[⍺α]|alpha"),
("Beta", r"[𝛽β]|beta"),
("Theta", r"[𝜃θ]|theta"),
("Gamma", r"[λγ]|gamma"),
("Delta", r"[δ]|delta"),
]
band_counts = pd.Series(
{
label: ps_freq.str.contains(pattern, case=False, regex=True, na=False).sum()
for label, pattern in band_patterns
}
).sort_values(ascending=True)
if band_counts.sum() == 0:
print(" No EEG parameter-space data found; skipping frequency_bands plot.")
return
set_plot_style()
fig, ax = plt.subplots(figsize=(7.2, 4.8), dpi=300)
bars = ax.barh(band_counts.index, band_counts.values, color="#0B7285", height=0.62)
ax.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax.spines[spine].set_visible(False)
ax.set_title("Frequency Band Prevalence", loc="left", pad=8, color="#1F1F1F")
ax.set_xlabel("Number of frequency-domain papers", color="#3A3A3A", labelpad=6)
ax.set_ylabel("")
ax.tick_params(axis="x", colors="#555555", length=0)
ax.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
max_count = int(band_counts.max()) if not band_counts.empty else 0
for bar, count in zip(bars, band_counts.values):
ax.text(
bar.get_width() + max_count * 0.015,
bar.get_y() + bar.get_height() / 2,
f"{count / freq_total * 100:.1f}%",
va="center",
ha="left",
fontsize=8,
color="#4A4A4A",
)
fig.tight_layout()
export_figure(fig, "fig4b_frequency_band_prevalence")
plt.close(fig)
def plot_multimodal_prevalence(df: pd.DataFrame) -> None:
multimodal_df = df[df["other_measures"].notna()].copy()
multimodal_total = len(multimodal_df)
if multimodal_total == 0:
print(" No multimodal studies found; skipping multimodal_prevalence plot.")
return
om = multimodal_df["other_measures"].astype(str).str.lower()
modalities = {
"ECG / HRV": om.str.contains(r"ecg|hrv|heart rate", na=False),
"EDA": om.str.contains(r"\beda\b|galvanic|gsr|skin conduct", na=False),
"Eye-tracking": om.str.contains(r"eye.?track|eyetrack", na=False),
"Blood pressure": om.str.contains(r"blood.?press", na=False),
"Skin temperature": om.str.contains(r"skin.?temp|temperature", na=False),
"PPG": om.str.contains(r"\bppg\b|photopleth", na=False),
"Respiration": om.str.contains(r"resp|breath", na=False),
"EMG": om.str.contains(r"\bemg\b|electromyo", na=False),
"Motion / GPS": om.str.contains(r"\bgps\b|motion|accel|inertial", na=False),
"EOG": om.str.contains(r"\beog\b|electrooculo", na=False),
"Cortisol": om.str.contains(r"cortisol", na=False),
}
modality_counts = pd.Series(
{name: mask.sum() for name, mask in modalities.items() if mask.sum() > 0}
).sort_values(ascending=True)
if modality_counts.empty:
print(
" No multimodal modality matches found; skipping multimodal_prevalence plot."
)
return
set_plot_style()
fig, ax = plt.subplots(figsize=(7.2, 4.8), dpi=300)
bars = ax.barh(
modality_counts.index, modality_counts.values, color="#2A9D8F", height=0.62
)
ax.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax.spines[spine].set_visible(False)
ax.set_title(
"Modality Prevalence in Multimodal Studies", loc="left", pad=8, color="#1F1F1F"
)
ax.set_xlabel("Number of multimodal studies", color="#3A3A3A", labelpad=6)
ax.set_ylabel("")
ax.tick_params(axis="x", colors="#555555", length=0)
ax.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
max_count = int(modality_counts.max()) if not modality_counts.empty else 0
for bar, count in zip(bars, modality_counts.values):
ax.text(
bar.get_width() + max_count * 0.015,
bar.get_y() + bar.get_height() / 2,
f"{count / multimodal_total * 100:.1f}%",
va="center",
ha="left",
fontsize=8,
color="#4A4A4A",
)
fig.tight_layout()
export_figure(fig, "fig5a_multimodal_modality_prevalence")
plt.close(fig)
def plot_multimodal_integration_pie(df: pd.DataFrame) -> None:
eeg_only = df["other_measures"].isna().sum()
multimodal = len(df) - eeg_only
integrated = df["Fusion EEG-Other Modalities"].eq(1.0).sum()
non_integrated = multimodal - integrated
if multimodal == 0:
print(" No multimodal studies found; skipping multimodal_integration plot.")
return
counts = pd.Series(
{
"EEG only": eeg_only,
"Multimodal without integration": non_integrated,
"Integrated multimodal": integrated,
}
)
set_plot_style()
palette = ["#16324F", "#A8E6CF", "#2A9D8F"]
fig, ax = plt.subplots(figsize=(6.8, 4.8), dpi=300)
wedges, texts, autotexts = ax.pie(
counts.values,
labels=counts.index,
colors=palette,
startangle=105,
autopct=lambda p: f"{p:.1f}%" if p >= 4 else "",
pctdistance=0.78,
labeldistance=1.04,
wedgeprops={"linewidth": 0.8, "edgecolor": "white"},
textprops={"color": "#2A2A2A", "fontsize": 8},
)
for wedge, t in zip(wedges, autotexts):
r, g, b, _ = wedge.get_facecolor()
luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
t.set_color("white" if luminance < 0.55 else "#1F1F1F")
t.set_fontsize(8)
ax.set_title(
"EEG-only vs Multimodal Integration", loc="left", pad=8, color="#1F1F1F"
)
ax.text(
0.5,
-0.08,
f"N = {len(df)}",
transform=ax.transAxes,
ha="center",
va="top",
fontsize=8,
color="#555555",
)
plt.tight_layout()
export_figure(fig, "fig5b_multimodal_integration_pie")
plt.close(fig)
def plot_consumer_grade_distribution(df: pd.DataFrame) -> None:
total = len(df)
grade_col = "System grade (medical vs consumer)"
if grade_col not in df.columns:
print(
f" Column '{grade_col}' not found; skipping consumer_grade_distribution plot."
)
return
grades = (
df[grade_col].fillna("NA").astype(str).str.strip().str.lower().value_counts()
)
counts = pd.Series(
{
"Consumer-grade": int(grades.get("consumer", 0)),
"Medical-grade": int(grades.get("medical", 0)),
"NA / Not reported": int(grades.get("na", 0) + grades.get("nan", 0)),
}
)
if counts.sum() == 0:
print(
" No EEG system grade data found; skipping consumer_grade_distribution plot."
)
return
set_plot_style()
plt.rcParams.update(
{
"axes.titlesize": 14,
"axes.labelsize": 12,
"xtick.labelsize": 11,
"ytick.labelsize": 11,
}
)
colors = ["#0B3C5D", "#2A9D8F", "#D7DEE3"]
fig, ax = plt.subplots(figsize=(7.2, 4.8), dpi=300)
bars = ax.barh(counts.index, counts.values, color=colors, height=0.62)
ax.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax.spines[spine].set_visible(False)
ax.set_title("EEG System Grade Distribution", loc="left", pad=8, color="#1F1F1F")
ax.set_xlabel("Number of studies", color="#3A3A3A", labelpad=6)
ax.set_ylabel("")
ax.tick_params(axis="x", colors="#555555", length=0)
ax.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
max_count = int(counts.max()) if not counts.empty else 0
for bar, count in zip(bars, counts.values):
pct_value = (count / total * 100) if total > 0 else 0
ax.text(
bar.get_width() + max_count * 0.015,
bar.get_y() + bar.get_height() / 2,
f"{pct_value:.1f}%",
va="center",
ha="left",
fontsize=10,
color="#4A4A4A",
)
fig.tight_layout()
export_figure(fig, "fig6b_consumer_grade_distribution")
plt.close(fig)
def plot_top_eeg_systems(df: pd.DataFrame, top_n: int = 12) -> None:
sys_counts = df["EEG_system"].dropna().astype(str).str.strip()
sys_counts = sys_counts[sys_counts != ""].value_counts()
if sys_counts.empty:
print(" No EEG system data found; skipping top_eeg_systems plot.")
return
top_counts = sys_counts.head(top_n).sort_values(ascending=True)
total = int(len(df))
set_plot_style()
plt.rcParams.update(
{
"axes.titlesize": 14,
"axes.labelsize": 12,
"xtick.labelsize": 11,
"ytick.labelsize": 10,
}
)
fig, ax = plt.subplots(figsize=(8.2, 5.6), dpi=300)
bars = ax.barh(top_counts.index, top_counts.values, color="#5E8CA8", height=0.62)
ax.grid(axis="x", color="#D9D7D0", linestyle="-", linewidth=0.6, alpha=0.55)
ax.set_axisbelow(True)
for spine in ["top", "right", "left", "bottom"]:
ax.spines[spine].set_visible(False)
ax.set_title("Top EEG Systems", loc="left", pad=8, color="#1F1F1F")
ax.set_xlabel("Number of studies", color="#3A3A3A", labelpad=6)
ax.set_ylabel("")
ax.tick_params(axis="x", colors="#555555", length=0)
ax.tick_params(axis="y", colors="#2A2A2A", length=0, pad=6)
max_count = int(top_counts.max()) if not top_counts.empty else 0
for bar, count in zip(bars, top_counts.values):
pct_value = (count / total * 100) if total > 0 else 0
ax.text(
bar.get_width() + max_count * 0.015,
bar.get_y() + bar.get_height() / 2,
f"{pct_value:.1f}%",
va="center",
ha="left",
fontsize=10,
color="#4A4A4A",
)
fig.tight_layout()
export_figure(fig, "fig6a_top_eeg_systems")
plt.close(fig)
def plot_data_availability(df: pd.DataFrame) -> None:
availability_col = "Data Availability"
year_col = "Year"
availability_map = {
0: "Not available",
1: "Available upon request",
2: "Openly available",
}
availability_frame = df[[year_col, availability_col]].copy()