From 7069072d88477b897b373f6d42b1b86330166c16 Mon Sep 17 00:00:00 2001 From: Stefan Mitic Date: Tue, 10 Mar 2020 11:28:35 -0400 Subject: [PATCH 1/5] fix: added check for value of Fs --- lib/matplotlib/axes/_axes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index d379e08fda10..31e548e83c6d 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7649,6 +7649,8 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, Z = np.flipud(Z) if xextent is None: + if Fs is None: + Fs = freqs[-1] * 2 # default set in mlab._spectral_helper() # padding is needed for first and last segment: pad_xextent = (NFFT-noverlap) / Fs / 2 xextent = np.min(t) - pad_xextent, np.max(t) + pad_xextent From cc753e7053f2a80b6a0903fff2ae0b6d6d20eff8 Mon Sep 17 00:00:00 2001 From: Stefan Mitic Date: Tue, 10 Mar 2020 11:28:57 -0400 Subject: [PATCH 2/5] test: created test for specgram Fs is none --- lib/matplotlib/tests/test_axes.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 47a028256640..10f889ac1126 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4166,6 +4166,17 @@ def test_specgram_angle(): scale="dB") +def test_specgram_fs_none(): + """ Test axes.specgram when Fs is None, should not throw error """ + try: + spec, freqs, t, im = plt.specgram(np.ones(300), Fs=None) + except Exception as e: + raise pytest.fail("DID RAISE {0}".format(e)) + + xmin, xmax, freq0, freq1 = im.get_extent() + assert xmin == 32 and xmax == 96 + + @image_comparison( ["psd_freqs.png", "csd_freqs.png", "psd_noise.png", "csd_noise.png"], remove_text=True, tol=0.002) From 428e2ad2a7319c52183267fc009b0e4a99430d14 Mon Sep 17 00:00:00 2001 From: Stefan Mitic Date: Tue, 31 Mar 2020 13:23:14 -0400 Subject: [PATCH 3/5] style: removed extraspaces from docstring --- lib/matplotlib/tests/test_axes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 10f889ac1126..921d55ec61e1 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4167,7 +4167,8 @@ def test_specgram_angle(): def test_specgram_fs_none(): - """ Test axes.specgram when Fs is None, should not throw error """ + """Test axes.specgram when Fs is None, should not throw error.""" + try: spec, freqs, t, im = plt.specgram(np.ones(300), Fs=None) except Exception as e: From b7df1aa7f073f0177e703c5dde9e472841e8b208 Mon Sep 17 00:00:00 2001 From: Stefan Mitic Date: Wed, 1 Apr 2020 18:58:56 -0400 Subject: [PATCH 4/5] fix: moved default Fs value statement --- lib/matplotlib/axes/_axes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 31e548e83c6d..ec06d15ab9bd 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7617,6 +7617,8 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, Fc = 0 # same default as in mlab._spectral_helper() if noverlap is None: noverlap = 128 # same default as in mlab.specgram() + if Fs is None: + Fs = 2 # same default as in mlab._spectral_helper() if mode == 'complex': raise ValueError('Cannot plot a complex specgram') @@ -7649,8 +7651,6 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, Z = np.flipud(Z) if xextent is None: - if Fs is None: - Fs = freqs[-1] * 2 # default set in mlab._spectral_helper() # padding is needed for first and last segment: pad_xextent = (NFFT-noverlap) / Fs / 2 xextent = np.min(t) - pad_xextent, np.max(t) + pad_xextent From 72597a31d7e4bc232350dc6c632b0ad5e1531cfc Mon Sep 17 00:00:00 2001 From: Stefan Mitic Date: Thu, 2 Apr 2020 13:57:46 -0400 Subject: [PATCH 5/5] test: removed try...except --- lib/matplotlib/tests/test_axes.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 921d55ec61e1..acc32bac243a 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4168,12 +4168,7 @@ def test_specgram_angle(): def test_specgram_fs_none(): """Test axes.specgram when Fs is None, should not throw error.""" - - try: - spec, freqs, t, im = plt.specgram(np.ones(300), Fs=None) - except Exception as e: - raise pytest.fail("DID RAISE {0}".format(e)) - + spec, freqs, t, im = plt.specgram(np.ones(300), Fs=None) xmin, xmax, freq0, freq1 = im.get_extent() assert xmin == 32 and xmax == 96