Question: I am working with audio using librosa, and I need to plot the spectrogram and waveform in the same display.

My code:

```
plt.figure(figsize=(14, 9))

plt.figure(1)

plt.subplot(211)
plt.title('Spectrogram')
librosa.display.specshow(stft_db, x_axis='time', y_axis='log')

plt.subplot(212)
plt.title('Audioform')
librosa.display.waveplot(y, sr=sr)

```

Using this code I get this plot

![](https://i.stack.imgur.com/MD4JU.png)

But I need something like this

![](https://i.stack.imgur.com/RAM2O.png)

Answer: 
According to librosa, you're able to provide the display methods with an axes to draw the item on, [specshow](https://librosa.github.io/librosa/generated/librosa.display.specshow.html#librosa.display.specshow), [waveplot](https://librosa.github.io/librosa/generated/librosa.display.waveplot.html). I'd recommend defining your matplotlib figure and subplots outright, and then giving librosa the axes to plot them on.

```
fig = plt.figure(figsize=(14, 9)) #This setups the figure
ax1 = fig.subplots() #Creates the Axes object to display one of the plots
ax2 = ax1.twinx() #Creates a second Axes object that shares the x-axis

librosa.display.specshow(stft_db, x_axis='time', y_axis='log', ax=ax1)
librosa.display.waveplot(y, sr=sr, ax=ax2)
plt.show()

```

There might be some more formatting to be done to get the desired look, I'd recommend taking a look at [this example](https://matplotlib.org/gallery/api/two_scales.html) from matplotlib, for a similar shared axes plot.
Instead of using subplots use the same axes of a single plot to display both the graphs. 

```py
fig = plt.figure(figsize=(14, 9))
ax = librosa.display.specshow(stft_db, x_axis='time', y_axis='log')
librosa.display.waveplot(y, sr=sr, ax=ax)
plt.show()

```