I am not very experienced in customizing matplotlib. I created the code by referring to this page. I think there is a better way to adjust the position as it is set manually.
import librosa
import librosa.display
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import matplotlib as mpl
file_name = '/content/test.wav'
wav, sr = librosa.load(file_name, sr=44100)
target_len = 1.5
fig = plt.figure(figsize=(12,3))
ax = fig.add_subplot(111)
librosa.display.waveplot(wav, sr, color='black')
ax.set_xlabel('Time (seconds)')
ax.set_ylabel('Amplitude')
ax.axvspan(0, target_len, color = 'magenta', alpha=0.5, zorder=-100)
ax.axvspan(target_len, target_len*2, color = 'yellow', alpha=0.5, zorder=-100)
ax.axvspan(target_len*2, target_len*3,color = 'blue', alpha=0.5, zorder=-100)
# t = fig.transFigure
# print(t)
a = ax.transAxes
print(a)
plt.text(0.25, 1.0, 'Audio 1', ha='center', va='top', transform=fig.transFigure)
plt.text(0.45, 1.0, 'Audio 2', ha='center', va='top', transform=fig.transFigure)
plt.text(0.70, 1.0, 'Audio 3', ha='center', va='top', transform=fig.transFigure)
rect1 = mpl.patches.Rectangle((0.0, 1.02), width=0.295, height=0.05, color="black", transform=ax.transAxes, clip_on=False)
rect2 = mpl.patches.Rectangle((0.30, 1.02), width=0.295, height=0.05, color="black", transform=ax.transAxes, clip_on=False)
rect3 = mpl.patches.Rectangle((0.60, 1.02), width=0.295, height=0.05, color="black", transform=ax.transAxes, clip_on=False)
ax.add_patch(rect1)
ax.add_patch(rect2)
ax.add_patch(rect3)
# plt.tight_layout()
plt.show()
BboxTransformTo(
TransformedBbox(
Bbox(x0=0.125, y0=0.125, x1=0.9, y1=0.88),
BboxTransformTo(
TransformedBbox(
Bbox(x0=0.0, y0=0.0, x1=12.0, y1=3.0),
Affine2D(
[[72. 0. 0.]
[ 0. 72. 0.]
[ 0. 0. 1.]])))))