mkkubins
(Marta )
May 15, 2021, 12:03pm
1
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
Awol
(Wol)
May 15, 2021, 7:06pm
2
I have exactly the same question!! How to add a colorbar with mne.vix.plot_topomap on non-evoked/raw data !!
Thank you!
Marc
(Marc)
May 17, 2021, 8:02am
3
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
mkkubins
(Marta )
May 17, 2021, 10:46am
4
Marc:
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
Yes, it’s working!! thank you so much for the help!
1 Like
it worked fine for me too thank you
stewie
(Stefan)
June 15, 2023, 4:40pm
6
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