How to suppress redundant colorbars when using EpochsArray.plot_psd_topomap()?

  • python 3.9
  • MNE version: 1.4.2
  • operating system: Windows 10
  • IDE: pycharm community

I’m trying to suppress redundant colorbars when using EpochsArray.plot_psd_topomap(). And I use the methods in https://github.com/mne-tools/mne-python/pull/11051, but I failed.

Here is my code:

def plot_psd_topomap(data, path)
    channels = mne.channels.make_standard_montage("GSN-HydroCel-129")
    info = mne.create_info(channels.ch_names, 512, 'eeg')
    info.set_montage("GSN-HydroCel-129")
    epochs = mne.EpochsArray(data, info)
    bands = [(0.5, 4, 'Delta'), (4, 8, 'Theta'), (8, 13, 'Alpha'), (13, 38, 'Beta')]
    fig = epochs.plot_psd_topomap(bands=bands, vlim='joint', dB=True)
    fig.savefig(path, dpi=300)

The result is :

And my expected result is:

How should I do?

this appears to be a bug. I’ve submitted a fix here:

In the short-term you could either:

  • install mne-python from that PR branch (pip install -U git+https://github.com/drammock/mne-python@fix-vlim-joint)
  • access the colorbar axes from the generated figure, and delete them manually:
# ...
fig = epochs.plot_psd_topomap(bands=bands, vlim='joint', dB=True)
xmax = max(ax.get_position().xmin for ax in fig.axes)
for ax in fig.axes:
    if ax.get_ylabel() == 'µV²/Hz (dB)' and ax.get_position().xmin != xmax:
        ax.remove()

Thank you! The codes above works.
By the way, the link of your first method https://github.com/drammock/mne-python@fix-vlim-joint is 404.

It’s not a URL, it’s a command-line argument to pip install (thus not expected to work in a browser). But nonetheless by now the command is out of date because the PR was merged and I reflexively deleted the branch. Now that it’s merged you can instead do

pip install -U git+https://github.com/mne-tools/mne-python

to install current main (instead of my PR branch)