【发布时间】:2021-10-10 17:27:40
【问题描述】:
我想使用输入数据制作子图
【问题讨论】:
标签: python matplotlib colorbar obspy
我想使用输入数据制作子图
【问题讨论】:
标签: python matplotlib colorbar obspy
我认为这只是将频谱图的“可映射”传递给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,因为you shouldn't use jet。
【讨论】:
plt.colorbar() 想要的可映射对象似乎在一个属性中。我试过spec.images[0],但由于某种原因那个东西是空的,结果它潜伏在spec.collections[0]中。我觉得obspy 可以让这更方便。