From 35a427085289b082f0cb230ebd7cd22359ef6241 Mon Sep 17 00:00:00 2001 From: Vinay Raghavan <42253618+vinaysraghavan@users.noreply.github.com> Date: Fri, 4 Apr 2025 19:00:53 -0400 Subject: [PATCH 1/2] Add example, Fix get_cmap Add to the example of plotting on the brain by plotting the atlas regions on the brain. Catch an exception caused by matplotlib 3.9 breaking plt.cm.get_cmap() and replacing it with plt.get_cmap() --- examples/brain_plotting/plot_intracranial_electrodes.py | 8 ++++++++ naplib/utils/surfdist.py | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/brain_plotting/plot_intracranial_electrodes.py b/examples/brain_plotting/plot_intracranial_electrodes.py index f502b26..db30108 100644 --- a/examples/brain_plotting/plot_intracranial_electrodes.py +++ b/examples/brain_plotting/plot_intracranial_electrodes.py @@ -122,4 +122,12 @@ fig, axes = plot_brain_overlay(brain, view='lateral') plt.show() +############################################################################### +# Directly plot brain region labels overlaid on the brain +brain = Brain('pial', subject_dir='./fsaverage/') + +brain.lh.overlay = brain.lh.labels +brain.rh.overlay = brain.rh.labels +fig, axes = plot_brain_overlay(brain, cmap='tab20', vmin=1, vmax=75) +plt.show() diff --git a/naplib/utils/surfdist.py b/naplib/utils/surfdist.py index 0db54a9..d8e1897 100644 --- a/naplib/utils/surfdist.py +++ b/naplib/utils/surfdist.py @@ -180,7 +180,10 @@ def surfdist_viz( # if cmap is given as string, translate to matplotlib cmap if isinstance(cmap, str): - cmap = plt.cm.get_cmap(cmap) + try: + cmap = plt.cm.get_cmap(cmap) + except AttributeError: + cmap = plt.get_cmap(cmap) if ax is None: premade_ax = False From eadf13a18e9d0edcfa60c809bcc797a169148aec Mon Sep 17 00:00:00 2001 From: Vinay Raghavan <42253618+vinaysraghavan@users.noreply.github.com> Date: Fri, 4 Apr 2025 19:03:20 -0400 Subject: [PATCH 2/2] More specificity --- examples/brain_plotting/plot_intracranial_electrodes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/brain_plotting/plot_intracranial_electrodes.py b/examples/brain_plotting/plot_intracranial_electrodes.py index db30108..6d19c9b 100644 --- a/examples/brain_plotting/plot_intracranial_electrodes.py +++ b/examples/brain_plotting/plot_intracranial_electrodes.py @@ -123,7 +123,7 @@ plt.show() ############################################################################### -# Directly plot brain region labels overlaid on the brain +# Directly plot Destrieux Atlas region labels overlaid on the brain brain = Brain('pial', subject_dir='./fsaverage/') brain.lh.overlay = brain.lh.labels