1

我想使用输入数据制作子图

4

1 回答 1

2

我认为这只是一个将频谱图的“可映射”传递给它的问题,plt.colorbar()以便它知道要为什么制作颜色条。棘手的是它有点隐藏在频谱图的属性中Axes

fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
ax1.plot(time, data1[0].data)
ax2.plot(time, data2.data)
spec = data2.spectrogram(axes=ax3,  # <-- Assign a name.
                         show=True,
                         samp_rate=20,
                         per_lap=0.5,
                         wlen=30,
                         log=True,
                         cmap='plasma',  # <-- Don't use jet :)
                         clip=(0.05, 0.2),
                        )
plt.xlabel('Time')
plt.ylabel('Frequency')

# More flexibility with the positioning:
cbar_ax = fig.add_axes([0.2, 0.0, 0.6, 0.05])  # Left, bottom, width, height.
cbar = fig.colorbar(spec.collections[0],  # <-- Get the mappable.
                    cax=cbar_ax,
                    orientation='horizontal')
cbar.set_label('Colorbar label')

plt.show()

这也显示了如何将颜色条放置在您想要的位置。我将您的颜色图更改为plasma因为您不应该使用jet.

于 2021-08-05T17:39:03.747 回答