How to plot multiple topomap in one figure?

Hi, I tried to plot topomap of six conditions in one figure, but failed in merging them together. How could I plot all of them in one figure? My code as shown bellow:

fig, axs = plt.subplots(6, 1, figsize=(18, 24), constrained_layout=True, sharex=True, sharey=True)
times = np.arange(-.050, .850, .100)
contrasts = ['contr1', 'contr2', 'contr3', 'contr4', 'contr5', 'contr6']
for ax, contr in zip(axs, contrasts):
    mne.grand_average(evokeds_diff[contr]).plot_topomap(times, average=0.100, ch_type='eeg', show_names=False, sensors=True, contours=False, colorbar=True, show=False)

plt.savefig('all_contrasts.png')
plt.show()

Thanks a lot.

I have tried to add “axes=ax” in mne function, but it popped out error message. I have to change the value of axs into 10 to fix the error. After that, the topomap became too small to see it clearly. So, I don’t think the axes value should be plugged into the mne function (The default value of axes in mne is “None”).

I am not quite sure I understand your problem, maybe the error message would be informative. But, I suspect that it has something to do with the fact that you want to plot a colorbar. You may be running out of axes too soon as the actual topomap and the colorbar need to occupy one axis each.

2 Likes

Thanks, Sotiris.

When I set the colorbar as False, I got a right picture, but without the colorbar. So, my next question is how could I put one colorbar on my figure.

Furthermore, when I write the title value, the results always wrong. The error message is "TypeError: Evoked.plot_topomap() got an unexpected keyword argument ‘title’ "

Thanks a lot.

I would start by changing fig, axes = plt.subplots(6, 1) to fig, axes = plt.subplots(6, len(times)+1), and pass colorbar=True. That should give you enough axes in each row for your evoked topomaps plus one extra for the colorbar. You’ll probably notice that the axis limits on each colorbar are slightly different, which means you shouldn’t show just one colorbar unless you provide the same fixed vlim values for each row. So now re-do the plot with a vlim value passed in too. If it looks OK, then you can remove the colorbars you don’t want (e.g., using axes[-1, -1].remove() would remove the bottom-right axes).

the title parameter was deprecated and removed. please use the matplotlib method fig.suptitle() instead.

1 Like

Thanks so much~