Thanks to visit codestin.com
Credit goes to github.com

Skip to content

flipping of imshow in specgram #17878

Closed
@TomFD

Description

@TomFD

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions