Description
Bug report
Bug summary
The function
matplotlib.pyplot.specgram
uses imshow internally to plot a spectrogram but does not set the origin. So someone can externally overwrite the standard behaviour and wonder, why the spectrogramm is flipped.
Unintensionally, this can even happen if another imshow was used before with different origin.
Code for reproduction
For reproduction, only the origin setting before the function call is added to the standard demo and flips the output.
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(19680801)
dt = 0.0005
t = np.arange(0.0, 20.0, dt)
s1 = np.sin(2 * np.pi * 100 * t)
s2 = 2 * np.sin(2 * np.pi * 400 * t)
s2[t <= 10] = s2[12 <= t] = 0
nse = 0.01 * np.random.random(size=len(t))
x = s1 + s2 + nse # the signal
NFFT = 1024 # the length of the windowing segments
Fs = int(1.0 / dt) # the sampling frequency
fig, (ax1, ax2) = plt.subplots(nrows=2)
ax1.plot(t, x)
# now overwrite the setting to get the spectrogramm flipped
plt.rcParams["image.origin"] = 'lower'
Pxx, freqs, bins, im = ax2.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900)
plt.show()
Actual outcome
Flipping of the spectrogram without flipping the y-axis.
Expected outcome
Non-flipping independent of origin setting of imshow or specifically, "image.origin" of rcParams.
Matplotlib version
3.2.1
conda installation
Suggestion
Someone with the knowledge should add the keyword origin='upper' to the relevant imshow command of specgram.