Mne.viz.plot_topomap and color bar

  • MNE-Python version: 0.23.dev0
  • operating system: Windows

Hi,
I have a question is it possible to add a color bar to mne.vix.plot_topomap? I am a bit struggle with this because every time when I am using fig.colorbar(im, ax=ax, shrink=0.6) it shows an error. I would like to add one color bar for all subplots.

Thanks

fig, ax = plt.subplots(nrows=1,ncols=4, figsize=(20, 10),sharex=True, sharey=True)
mne.viz.plot_topomap(delta_baseline[0],place,names=chs,show_names=True,cmap='coolwarm',axes=ax[0])
mne.viz.plot_topomap(delta_x[0],place,names=chs,show_names=True,cmap='coolwarm',axes=ax[1])
mne.viz.plot_topomap(delta_y[0],place,names=chs,show_names=True,cmap='coolwarm',axes=ax[2])
mne.viz.plot_topomap(delta_z[0],place,names=chs,show_names=True,cmap='coolwarm',axes=ax[3])
ax[0].set_title('Baseline',fontweight='bold')
ax[1].set_title('x', fontweight='bold')
ax[2].set_title('y', fontweight='bold')
ax[3].set_title('z', fontweight='bold')
fig.suptitle('Delta',x=0.1,y=0.53,fontweight='bold')
1 Like

I have exactly the same question!! How to add a colorbar with mne.vix.plot_topomap on non-evoked/raw data !!
Thank you!

Does this help you? To compare multiple topomaps, I provide vmin and vmax. Then you can refer to any topomap for the creation of the colorbar.

fig,(ax1,ax2) = plt.subplots(ncols=2)
im,cm   = mne.viz.plot_topomap(x1, info, axes=ax1,show=False,vmin=vmin,vmax=vmax)   
im,cm   = mne.viz.plot_topomap(x2, info, axes=ax2,show=False,vmin=vmin,vmax=vmax)   
# manually fiddle the position of colorbar
ax_x_start = 0.95
ax_x_width = 0.04
ax_y_start = 0.1
ax_y_height = 0.9
cbar_ax = fig.add_axes([ax_x_start, ax_y_start, ax_x_width, ax_y_height])
clb = fig.colorbar(im, cax=cbar_ax)
clb.ax.set_title(unit_label,fontsize=fontsize) # title on top of colorbar

This approach is tedious, but also very flexible. (Code not tested.)

4 Likes

Yes, it’s working!! thank you so much for the help! :slight_smile:

1 Like

it worked fine for me too thank you

Is there a similar option to do this for mne.viz.plot_evoked_topomap?

I am trying but cannot figure it out. I will create a new post for this