Skip to content

colorbar=False is ignored in plot_psds_topomap() #12852

@tsbinns

Description

@tsbinns

Description of the problem

Forum post: https://mne.discourse.group/t/remove-colorbar/9323

The colorbar flag in plot_psds_topomap() (called by *Spectrum.plot_topomap()) is overwritten by the logic on line 2838:

mne-python/mne/viz/topomap.py

Lines 2834 to 2840 in 670330a

# loop over subplots/frequency bands
for ax, _mask, _data, (title, (fmin, fmax)) in zip(
axes, freq_masks, band_data, bands.items()
):
colorbar = (not joint_vlim) or ax == axes[-1]
_plot_topomap_multi_cbar(
_data,

which means that calling colorbar=False is ignored.

This could be resolved with something like:

plot_colorbar = False if not colorbar else (not joint_vlim) or ax == axes[-1]
_plot_topomap_multi_cbar(
    ...,
    colorbar=plot_colorbar,
    ...
)

Steps to reproduce

import mne
from mne.datasets import sample

data_path = sample.data_path()
meg_path = data_path / "MEG" / "sample"
fname_raw = meg_path / "sample_audvis_raw.fif"
fname_event = meg_path / "sample_audvis_raw-eve.fif"
raw = mne.io.read_raw_fif(fname_raw)
events = mne.read_events(fname_event)
picks = mne.pick_types(raw.info, meg="grad")

epochs = mne.Epochs(
    raw,
    events,
    event_id=1,
    tmin=-0.2,
    tmax=1,
    picks=picks,
    baseline=(None, 0),
    reject=dict(grad=4000e-13),
    preload=True,
)

epochs.compute_psd().plot_topomap(colorbar=False)

Link to data

No response

Expected results

There should be no colorbars on the plots.

Actual results

Colorbars are still present (same behaviour as if colorbar=True was called).

Additional information

Platform Windows-11-10.0.22631-SP0
Python 3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:24:51) [MSC v.1940 64 bit (AMD64)]
Executable c:\Users\tsbin\anaconda3\envs\mne\python.exe
CPU Intel64 Family 6 Model 154 Stepping 3, GenuineIntel (16 cores)
Memory 31.7 GB

Core
├☑ mne 1.9.0.dev20+g013d6c9f6 (devel, latest release is 1.8.0)
├☑ numpy 1.26.4 (OpenBLAS 0.3.23.dev with 16 threads)
├☑ scipy 1.14.1
└☑ matplotlib 3.9.2 (backend=qtagg)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions