Skip to content

Commit 97d9cd1

Browse files
authored
Merge pull request matplotlib#16947 from Stefan-Mitic/issue/9100
Fix missing parameter initialization in Axes.specgram()
2 parents 99340e2 + 72597a3 commit 97d9cd1

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/matplotlib/axes/_axes.py

+2
Original file line numberDiff line numberDiff line change
@@ -7462,6 +7462,8 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
74627462
Fc = 0 # same default as in mlab._spectral_helper()
74637463
if noverlap is None:
74647464
noverlap = 128 # same default as in mlab.specgram()
7465+
if Fs is None:
7466+
Fs = 2 # same default as in mlab._spectral_helper()
74657467

74667468
if mode == 'complex':
74677469
raise ValueError('Cannot plot a complex specgram')

lib/matplotlib/tests/test_axes.py

+7
Original file line numberDiff line numberDiff line change
@@ -4211,6 +4211,13 @@ def test_specgram_angle():
42114211
scale="dB")
42124212

42134213

4214+
def test_specgram_fs_none():
4215+
"""Test axes.specgram when Fs is None, should not throw error."""
4216+
spec, freqs, t, im = plt.specgram(np.ones(300), Fs=None)
4217+
xmin, xmax, freq0, freq1 = im.get_extent()
4218+
assert xmin == 32 and xmax == 96
4219+
4220+
42144221
@image_comparison(
42154222
["psd_freqs.png", "csd_freqs.png", "psd_noise.png", "csd_noise.png"],
42164223
remove_text=True, tol=0.002)

0 commit comments

Comments
 (0)