0

I am using python and want to draw a graph includes 5 images, which looks like this: enter image description here Here is my codes:

fig, axes = plt.subplots(nrows=1, ncols=5, figsize=(50, 5))

ax = axes[0]
ax.title.set_text('1')
im,_ = mne.viz.topomap.plot_topomap(data_fft[0],l.pos,show_names=True,names=locs,axes=ax,cmap='Spectral_r',show=False)

ax = axes[1]
ax.title.set_text('2')
im,_ = mne.viz.topomap.plot_topomap(data_fft[1],l.pos,show_names=True,names=locs,axes=ax,cmap='Spectral_r',show=False)

ax = axes[2]
ax.title.set_text('3')
im,_ = mne.viz.topomap.plot_topomap(data_fft[2],l.pos,show_names=True,names=locs,axes=ax,cmap='Spectral_r',show=False)

ax = axes[3]
ax.title.set_text('4')
im,_ = mne.viz.topomap.plot_topomap(data_fft[3],l.pos,show_names=True,names=locs,axes=ax,cmap='Spectral_r',show=False)

ax = axes[4]
ax.title.set_text('5')
im,_ = mne.viz.topomap.plot_topomap(data_fft[4],l.pos,show_names=True,names=locs,axes=ax,cmap='Spectral_r',show=True)

How to add a colorbar under this graph? I have tried fig.colorbar(im, ax=axes, orientation='vertical'), but the error: AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'

HAO CHEN
  • 1,209
  • 3
  • 18
  • 32
  • 2
    Have you tried fig.colorbar(ax =axes[0]) or any other index [since the axes is an nxarray]? – cvanelteren Jun 21 '19 at 17:01
  • I second cvanelteren's comment and also you can try manually setting your colorer axis? https://stackoverflow.com/questions/35611806/add-axis-to-colorbar-in-python-matplotlib – BenT Jun 21 '19 at 17:20
  • In `fig.colorbar(im, ax=axes, orientation='vertical')`, `axes` is an `np.array` of subplots, not an individual subplot, which is why the `AttributeError` occurs there, and not when you access the specific subplot with `ax = axes[3]`. – Trenton McKinney Oct 06 '20 at 17:00

0 Answers0