如何为子图添加颜色条

时间:2019-06-21 16:17:01

标签: python matplotlib plot

我正在使用python并想绘制一个包含5张图像的图形,如下所示: enter image description here 这是我的代码:

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)

如何在此图表下添加颜色栏? 我尝试过fig.colorbar(im, ax=axes, orientation='vertical'),但错误:AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'

0 个答案:

没有答案