From 77a2b67ef0b0340f12ab79b55a61c88acdf65ec6 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 10 Jul 2020 12:43:30 +0100 Subject: [PATCH 01/26] Link to style-file example page in docs --- tutorials/introductory/customizing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/introductory/customizing.py b/tutorials/introductory/customizing.py index 97baedda6427..ab761fb8bcaf 100644 --- a/tutorials/introductory/customizing.py +++ b/tutorials/introductory/customizing.py @@ -12,7 +12,8 @@ ` file (which is read at startup to configure Matplotlib). -There are a number of pre-defined styles `provided by Matplotlib`_. For +There are a number of pre-defined styles :doc:`provided by Matplotlib +`. For example, there's a pre-defined style called "ggplot", which emulates the aesthetics of ggplot_ (a popular plotting package for R_). To use this style, just add: @@ -202,4 +203,3 @@ # # .. _ggplot: https://ggplot2.tidyverse.org/ # .. _R: https://www.r-project.org/ -# .. _provided by Matplotlib: https://github.com/matplotlib/matplotlib/tree/master/lib/matplotlib/mpl-data/stylelib From cc4a4db39d1448b1c1649286bd4b90f62014422d Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sat, 11 Jul 2020 16:37:31 -0400 Subject: [PATCH 02/26] Force origin='upper' in specgram function Specify origin='upper' in call to imshow within specgram to override rcparams setting for origin without changing rcparams itself. Delete origin from kwargs so there are not two occurrences of the origin parameter in the call to imshow (this also means the origin kwarg cannot be changed by the caller). --- lib/matplotlib/axes/_axes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 40cd2aefa911..f20d17bfa37c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7548,8 +7548,10 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, xmin, xmax = xextent freqs += Fc extent = xmin, xmax, freqs[0], freqs[-1] + + kwargs.pop('origin', None) im = self.imshow(Z, cmap, extent=extent, vmin=vmin, vmax=vmax, - **kwargs) + origin='upper', **kwargs) self.axis('auto') return spec, freqs, t, im From b5ef28ffe03eaff095582eb144a94046144afbbc Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sat, 11 Jul 2020 23:46:08 -0400 Subject: [PATCH 03/26] DOC: indicate that origin is force set to upper --- lib/matplotlib/axes/_axes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index f20d17bfa37c..0f70dcd4f7e2 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7464,7 +7464,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, **kwargs Additional keyword arguments are passed on to `~.axes.Axes.imshow` - which makes the specgram image. + which makes the specgram image. The origin kwarg is ignored. Returns ------- @@ -7501,6 +7501,9 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, ----- The parameters *detrend* and *scale_by_freq* do only apply when *mode* is set to 'psd'. + + The origin of the plot is forced to 'upper'. The origin rcParam and + the value of the origin kwarg, if passed, are ignored. """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() From 3ee213194688f51be531c30d064b758b277c11d8 Mon Sep 17 00:00:00 2001 From: Theodor Athanasiadis Date: Sun, 12 Jul 2020 18:34:15 +0300 Subject: [PATCH 04/26] Adding test for issue 17878 --- lib/matplotlib/tests/test_axes.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index cbc6a5cdd4a5..fbda76985047 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4099,6 +4099,22 @@ def test_specgram_fs_none(): assert xmin == 32 and xmax == 96 +@check_figures_equal(extensions=["png"]) +def test_specgram_origin(fig_test, fig_ref): + """Test that specgram ignores origin='lower' and always uses origin='upper'.""" + t = np.arange(0.0, 500) + signal = np.sin(2 * np.pi * 100 * t) + + # Reference: First graph using default origin in imshow (upper), + fig_ref.subplots().specgram(signal) + + # Try to overwrite the setting trying to flip the specgram + plt.rcParams["image.origin"] = 'lower' + + # Test: origin='lower' should be ignored + fig_test.subplots().specgram(signal) + + @image_comparison( ["psd_freqs.png", "csd_freqs.png", "psd_noise.png", "csd_noise.png"], remove_text=True, tol=0.002) From 9aab32047034e09edd9b3ffefb5f21965ccdae48 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sun, 12 Jul 2020 11:09:37 -0400 Subject: [PATCH 05/26] DOC: Change rcParam from 'origin' to 'image.origin' --- 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 0f70dcd4f7e2..b705d4624f7c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7502,8 +7502,8 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, The parameters *detrend* and *scale_by_freq* do only apply when *mode* is set to 'psd'. - The origin of the plot is forced to 'upper'. The origin rcParam and - the value of the origin kwarg, if passed, are ignored. + The origin of the plot is forced to 'upper'. The image.origin rcParam + and the value of the origin kwarg, if passed, are ignored. """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() From 67df84340e2b7d506c90a78c2f4338438df769a1 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sun, 12 Jul 2020 12:20:43 -0400 Subject: [PATCH 06/26] TST: try changing origin in specgram call --- lib/matplotlib/tests/test_axes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index fbda76985047..67b05d5a2ee2 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4102,8 +4102,10 @@ def test_specgram_fs_none(): @check_figures_equal(extensions=["png"]) def test_specgram_origin(fig_test, fig_ref): """Test that specgram ignores origin='lower' and always uses origin='upper'.""" - t = np.arange(0.0, 500) - signal = np.sin(2 * np.pi * 100 * t) + t = np.arange(500) + signal = np.sin(t) + + plt.rcParams["image.origin"] = 'upper' # Reference: First graph using default origin in imshow (upper), fig_ref.subplots().specgram(signal) @@ -4112,7 +4114,7 @@ def test_specgram_origin(fig_test, fig_ref): plt.rcParams["image.origin"] = 'lower' # Test: origin='lower' should be ignored - fig_test.subplots().specgram(signal) + fig_test.subplots().specgram(signal, origin='lower') @image_comparison( From 48288f864cea42902ff3a77e1053f1861baeeb67 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sun, 12 Jul 2020 13:22:48 -0400 Subject: [PATCH 07/26] Document behavior change for specgram --- doc/api/next_api_changes/behavior/17897-KLP.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 doc/api/next_api_changes/behavior/17897-KLP.rst diff --git a/doc/api/next_api_changes/behavior/17897-KLP.rst b/doc/api/next_api_changes/behavior/17897-KLP.rst new file mode 100644 index 000000000000..0d7aef70c1d9 --- /dev/null +++ b/doc/api/next_api_changes/behavior/17897-KLP.rst @@ -0,0 +1,11 @@ +pyplot.specgram uses origin='upper' even if an different kwarg or rcParam value is set +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Previously if ``image.origin`` was set to something other than upper or if +the ``origin`` kwarg was passed with a value other than upper, the spectrogram +itself would flip, but the axes would remain oriented for an origin value +of 'upper', so that the resulting plot was incorrectly labelled. + +Now, the ``origin`` kwarg and ``image.origin`` rcParam are ignored and the +function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that +the axes are correct for the plotted spectrogram. From ef4c5dc0803567f2484cfbfd32ee565bc8d1c95b Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sun, 12 Jul 2020 13:22:48 -0400 Subject: [PATCH 08/26] Document api behavior change --- doc/api/next_api_changes/behavior/17897-KLP.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 doc/api/next_api_changes/behavior/17897-KLP.rst diff --git a/doc/api/next_api_changes/behavior/17897-KLP.rst b/doc/api/next_api_changes/behavior/17897-KLP.rst new file mode 100644 index 000000000000..0d7aef70c1d9 --- /dev/null +++ b/doc/api/next_api_changes/behavior/17897-KLP.rst @@ -0,0 +1,11 @@ +pyplot.specgram uses origin='upper' even if an different kwarg or rcParam value is set +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Previously if ``image.origin`` was set to something other than upper or if +the ``origin`` kwarg was passed with a value other than upper, the spectrogram +itself would flip, but the axes would remain oriented for an origin value +of 'upper', so that the resulting plot was incorrectly labelled. + +Now, the ``origin`` kwarg and ``image.origin`` rcParam are ignored and the +function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that +the axes are correct for the plotted spectrogram. From 45ce308af4f8707f4adbbb32543244cb6d467a40 Mon Sep 17 00:00:00 2001 From: Theodor Athanasiadis Date: Sun, 12 Jul 2020 20:45:40 +0300 Subject: [PATCH 09/26] Reduced line length in test_axes.py --- lib/matplotlib/tests/test_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 67b05d5a2ee2..e2c3dd5ad898 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4101,7 +4101,7 @@ def test_specgram_fs_none(): @check_figures_equal(extensions=["png"]) def test_specgram_origin(fig_test, fig_ref): - """Test that specgram ignores origin='lower' and always uses origin='upper'.""" + """Test that specgram ignores origin='lower' and always uses 'upper'.""" t = np.arange(500) signal = np.sin(t) From 8d24ff771164c6d43963b3a338360c562faedeb3 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sun, 12 Jul 2020 17:07:44 -0400 Subject: [PATCH 10/26] Raise exception if origin kwarg passed to specgram This ensures the origin kwarg is not silently ignored if passed to pyplot.specgram. --- doc/api/next_api_changes/behavior/17897-KLP.rst | 4 ++-- lib/matplotlib/axes/_axes.py | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/api/next_api_changes/behavior/17897-KLP.rst b/doc/api/next_api_changes/behavior/17897-KLP.rst index 0d7aef70c1d9..9b8ee78c7e8a 100644 --- a/doc/api/next_api_changes/behavior/17897-KLP.rst +++ b/doc/api/next_api_changes/behavior/17897-KLP.rst @@ -6,6 +6,6 @@ the ``origin`` kwarg was passed with a value other than upper, the spectrogram itself would flip, but the axes would remain oriented for an origin value of 'upper', so that the resulting plot was incorrectly labelled. -Now, the ``origin`` kwarg and ``image.origin`` rcParam are ignored and the -function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that +Now, the ``origin`` kwarg is not supported and the ``image.origin`` rcParam is ignored. +The function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that the axes are correct for the plotted spectrogram. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index b705d4624f7c..434699ca32be 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7464,8 +7464,8 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, **kwargs Additional keyword arguments are passed on to `~.axes.Axes.imshow` - which makes the specgram image. The origin kwarg is ignored. - + which makes the specgram image. The origin keyword argument + is not supported. Returns ------- spectrum : 2-D array @@ -7503,7 +7503,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, is set to 'psd'. The origin of the plot is forced to 'upper'. The image.origin rcParam - and the value of the origin kwarg, if passed, are ignored. + is ignored and passing origin as a keyword argument raises a `TypeError.` """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() @@ -7552,7 +7552,10 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, freqs += Fc extent = xmin, xmax, freqs[0], freqs[-1] - kwargs.pop('origin', None) + if 'origin' in kwargs: + raise TypeError("specgram() got an unexpected keyword argument " + "'origin'") + im = self.imshow(Z, cmap, extent=extent, vmin=vmin, vmax=vmax, origin='upper', **kwargs) self.axis('auto') From 9cf10ddc838ce1a7d19b2310bf5037ff732712aa Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sun, 12 Jul 2020 17:24:59 -0400 Subject: [PATCH 11/26] TST: passing origin kwarg to specgram should fail The function pyplot.specgram should raise a TypeError if origin is passed as a keyword argument. --- lib/matplotlib/tests/test_axes.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 67b05d5a2ee2..e6d4d28b1cc4 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4100,8 +4100,8 @@ def test_specgram_fs_none(): @check_figures_equal(extensions=["png"]) -def test_specgram_origin(fig_test, fig_ref): - """Test that specgram ignores origin='lower' and always uses origin='upper'.""" +def test_specgram_origin_rcparam(fig_test, fig_ref): + """Test that specgram ignores the image.origin rcParam""" t = np.arange(500) signal = np.sin(t) @@ -4114,7 +4114,16 @@ def test_specgram_origin(fig_test, fig_ref): plt.rcParams["image.origin"] = 'lower' # Test: origin='lower' should be ignored - fig_test.subplots().specgram(signal, origin='lower') + fig_test.subplots().specgram(signal) + + +@pytest.mark.xfail(strict=True) +def test_specgram_origin_kwarg(): + """Ensure passing origin as a kwarg raises an exception.""" + t = np.arange(500) + signal = np.sin(t) + + plt.specgram(signal, origin='lower') @image_comparison( From 054ed06778db587c32b80e734a082a24f6893558 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sun, 12 Jul 2020 17:57:51 -0400 Subject: [PATCH 12/26] Shorten long line --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 434699ca32be..35f410a4503b 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7503,7 +7503,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, is set to 'psd'. The origin of the plot is forced to 'upper'. The image.origin rcParam - is ignored and passing origin as a keyword argument raises a `TypeError.` + is ignored. Passing origin as a keyword argument raises a `TypeError.` """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() From 326ce3ea6da80b41650fb71c76d0939ddccdbd7a Mon Sep 17 00:00:00 2001 From: kate-perkins Date: Mon, 13 Jul 2020 17:40:13 -0400 Subject: [PATCH 13/26] Fix documentation build error Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 35f410a4503b..a06ed1163e05 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7503,7 +7503,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, is set to 'psd'. The origin of the plot is forced to 'upper'. The image.origin rcParam - is ignored. Passing origin as a keyword argument raises a `TypeError.` + is ignored. Passing origin as a keyword argument raises a `TypeError`. """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() From d5959b51d009e10cd892ad2845a37a313affd998 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Mon, 13 Jul 2020 18:31:39 -0400 Subject: [PATCH 14/26] DOC: Remove note that origin='upper' in specgram This note referenced the call to imshow inside of specgram, which might confuse users who do not know the implementation of specgram. --- lib/matplotlib/axes/_axes.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index a06ed1163e05..9a9e5f84e0d5 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7501,9 +7501,6 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, ----- The parameters *detrend* and *scale_by_freq* do only apply when *mode* is set to 'psd'. - - The origin of the plot is forced to 'upper'. The image.origin rcParam - is ignored. Passing origin as a keyword argument raises a `TypeError`. """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() From c9e11544f421f4e0d23e9c28912da5474e2a6ec8 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 08:49:01 -0400 Subject: [PATCH 15/26] Shorten title and spell out keyword argument --- doc/api/next_api_changes/behavior/17897-KLP.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/doc/api/next_api_changes/behavior/17897-KLP.rst b/doc/api/next_api_changes/behavior/17897-KLP.rst index 9b8ee78c7e8a..2b99ee011622 100644 --- a/doc/api/next_api_changes/behavior/17897-KLP.rst +++ b/doc/api/next_api_changes/behavior/17897-KLP.rst @@ -1,11 +1,9 @@ -pyplot.specgram uses origin='upper' even if an different kwarg or rcParam value is set -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pyplot.specgram always uses origin='upper' +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Previously if ``image.origin`` was set to something other than upper or if -the ``origin`` kwarg was passed with a value other than upper, the spectrogram -itself would flip, but the axes would remain oriented for an origin value +Previously if ``image.origin`` was set to something other than 'upper' or if +the ``origin`` keyword argument was passed with a value other than 'upper', the spectrogram itself would flip, but the axes would remain oriented for an origin value of 'upper', so that the resulting plot was incorrectly labelled. -Now, the ``origin`` kwarg is not supported and the ``image.origin`` rcParam is ignored. -The function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that -the axes are correct for the plotted spectrogram. +Now, the ``origin`` keyword argument is not supported and the ``image.origin`` rcParam +is ignored. The function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that the axes are correct for the plotted spectrogram. From d0968be2f32aab046090e5b21b86864b36b5f960 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 09:25:12 -0400 Subject: [PATCH 16/26] TST: change from pytest xfail to pytest raises Passing origin as a keyword argument should raise a type error, so test_specgram_origin_kwarg should raise an exception. Therefore, raises is a more precise check than xfail. --- lib/matplotlib/tests/test_axes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a7a4b2561a5b..791274704d43 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4117,13 +4117,13 @@ def test_specgram_origin_rcparam(fig_test, fig_ref): fig_test.subplots().specgram(signal) -@pytest.mark.xfail(strict=True) def test_specgram_origin_kwarg(): - """Ensure passing origin as a kwarg raises an exception.""" + """Ensure passing origin as a kwarg raises a TypeError.""" t = np.arange(500) signal = np.sin(t) - plt.specgram(signal, origin='lower') + with pytest.raises(TypeError): + plt.specgram(signal, origin='lower') @image_comparison( From e4249e08fd19b378b98229820f0ef90a34413f7f Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 09:27:43 -0400 Subject: [PATCH 17/26] DOC: Add blank line after kwargs parameter --- lib/matplotlib/axes/_axes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 9a9e5f84e0d5..867993fe495c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7466,6 +7466,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, Additional keyword arguments are passed on to `~.axes.Axes.imshow` which makes the specgram image. The origin keyword argument is not supported. + Returns ------- spectrum : 2-D array From 5633a4507bfa9ff0f143b8ce6ddbfeab7b025233 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 09:31:46 -0400 Subject: [PATCH 18/26] Remove whitespace on blank line --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 867993fe495c..4e2c1cab9173 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7466,7 +7466,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, Additional keyword arguments are passed on to `~.axes.Axes.imshow` which makes the specgram image. The origin keyword argument is not supported. - + Returns ------- spectrum : 2-D array From 2310ff566940f4cf5f85e41d1087fdbe9e1b285e Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Sun, 12 Jul 2020 17:57:51 -0400 Subject: [PATCH 19/26] Shorten long line --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 434699ca32be..35f410a4503b 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7503,7 +7503,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, is set to 'psd'. The origin of the plot is forced to 'upper'. The image.origin rcParam - is ignored and passing origin as a keyword argument raises a `TypeError.` + is ignored. Passing origin as a keyword argument raises a `TypeError.` """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() From f8afa1405256919b3e2153ff6d1833c7cacd006c Mon Sep 17 00:00:00 2001 From: kate-perkins Date: Mon, 13 Jul 2020 17:40:13 -0400 Subject: [PATCH 20/26] Fix documentation build error Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 35f410a4503b..a06ed1163e05 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7503,7 +7503,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, is set to 'psd'. The origin of the plot is forced to 'upper'. The image.origin rcParam - is ignored. Passing origin as a keyword argument raises a `TypeError.` + is ignored. Passing origin as a keyword argument raises a `TypeError`. """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() From 007eaaefbda5042fed2290cc5b2c817220cb3af9 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Mon, 13 Jul 2020 18:31:39 -0400 Subject: [PATCH 21/26] DOC: Remove note that origin='upper' in specgram This note referenced the call to imshow inside of specgram, which might confuse users who do not know the implementation of specgram. --- lib/matplotlib/axes/_axes.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index a06ed1163e05..9a9e5f84e0d5 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7501,9 +7501,6 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, ----- The parameters *detrend* and *scale_by_freq* do only apply when *mode* is set to 'psd'. - - The origin of the plot is forced to 'upper'. The image.origin rcParam - is ignored. Passing origin as a keyword argument raises a `TypeError`. """ if NFFT is None: NFFT = 256 # same default as in mlab.specgram() From 3f06646870e0333bec4d983748b23b8e292f6aa1 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 08:49:01 -0400 Subject: [PATCH 22/26] Shorten title and spell out keyword argument --- doc/api/next_api_changes/behavior/17897-KLP.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/doc/api/next_api_changes/behavior/17897-KLP.rst b/doc/api/next_api_changes/behavior/17897-KLP.rst index 9b8ee78c7e8a..2b99ee011622 100644 --- a/doc/api/next_api_changes/behavior/17897-KLP.rst +++ b/doc/api/next_api_changes/behavior/17897-KLP.rst @@ -1,11 +1,9 @@ -pyplot.specgram uses origin='upper' even if an different kwarg or rcParam value is set -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pyplot.specgram always uses origin='upper' +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Previously if ``image.origin`` was set to something other than upper or if -the ``origin`` kwarg was passed with a value other than upper, the spectrogram -itself would flip, but the axes would remain oriented for an origin value +Previously if ``image.origin`` was set to something other than 'upper' or if +the ``origin`` keyword argument was passed with a value other than 'upper', the spectrogram itself would flip, but the axes would remain oriented for an origin value of 'upper', so that the resulting plot was incorrectly labelled. -Now, the ``origin`` kwarg is not supported and the ``image.origin`` rcParam is ignored. -The function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that -the axes are correct for the plotted spectrogram. +Now, the ``origin`` keyword argument is not supported and the ``image.origin`` rcParam +is ignored. The function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that the axes are correct for the plotted spectrogram. From d79202f4c4fe22deb79271d571051b62e798bf19 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 09:25:12 -0400 Subject: [PATCH 23/26] TST: change from pytest xfail to pytest raises Passing origin as a keyword argument should raise a type error, so test_specgram_origin_kwarg should raise an exception. Therefore, raises is a more precise check than xfail. --- lib/matplotlib/tests/test_axes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index e6d4d28b1cc4..170650b2cd26 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4117,13 +4117,13 @@ def test_specgram_origin_rcparam(fig_test, fig_ref): fig_test.subplots().specgram(signal) -@pytest.mark.xfail(strict=True) def test_specgram_origin_kwarg(): - """Ensure passing origin as a kwarg raises an exception.""" + """Ensure passing origin as a kwarg raises a TypeError.""" t = np.arange(500) signal = np.sin(t) - plt.specgram(signal, origin='lower') + with pytest.raises(TypeError): + plt.specgram(signal, origin='lower') @image_comparison( From 3e6aa01808baf875c12f03b4ec347d138860fb6f Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 09:27:43 -0400 Subject: [PATCH 24/26] DOC: Add blank line after kwargs parameter --- lib/matplotlib/axes/_axes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 9a9e5f84e0d5..867993fe495c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7466,6 +7466,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, Additional keyword arguments are passed on to `~.axes.Axes.imshow` which makes the specgram image. The origin keyword argument is not supported. + Returns ------- spectrum : 2-D array From 3aed2cfa0ccaf067719fd62d6f45cc60975bcc46 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 09:31:46 -0400 Subject: [PATCH 25/26] Remove whitespace on blank line --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 867993fe495c..4e2c1cab9173 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7466,7 +7466,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, Additional keyword arguments are passed on to `~.axes.Axes.imshow` which makes the specgram image. The origin keyword argument is not supported. - + Returns ------- spectrum : 2-D array From f958e88421d09e6abf5f0ce8fbf6ae7a78f76719 Mon Sep 17 00:00:00 2001 From: Kate Perkins Date: Tue, 14 Jul 2020 20:36:36 -0400 Subject: [PATCH 26/26] Wrap lines --- doc/api/next_api_changes/behavior/17897-KLP.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/api/next_api_changes/behavior/17897-KLP.rst b/doc/api/next_api_changes/behavior/17897-KLP.rst index 2b99ee011622..8ebcdc6a297a 100644 --- a/doc/api/next_api_changes/behavior/17897-KLP.rst +++ b/doc/api/next_api_changes/behavior/17897-KLP.rst @@ -2,8 +2,10 @@ pyplot.specgram always uses origin='upper' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Previously if ``image.origin`` was set to something other than 'upper' or if -the ``origin`` keyword argument was passed with a value other than 'upper', the spectrogram itself would flip, but the axes would remain oriented for an origin value +the ``origin`` keyword argument was passed with a value other than 'upper', the +spectrogram itself would flip, but the axes would remain oriented for an origin value of 'upper', so that the resulting plot was incorrectly labelled. Now, the ``origin`` keyword argument is not supported and the ``image.origin`` rcParam -is ignored. The function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, so that the axes are correct for the plotted spectrogram. +is ignored. The function matplotlib.pyplot.specgram is forced to use ``origin='upper'``, +so that the axes are correct for the plotted spectrogram.