From e39e3cfc2f3f44083309c918121f594b03fdd287 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Mon, 12 Aug 2019 19:05:37 -0500 Subject: [PATCH 1/3] Rename annotate parameter to match upstream Run boilerplate.py change version rename takes effect Co-Authored-By: Thomas A Caswell Release note of variable change Rebased onto newer master Address doc building Apply suggested language change for release note Co-Authored-By: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- doc/api/next_api_changes/2019-08-12-KS.rst | 8 ++++++++ lib/matplotlib/axes/_axes.py | 5 +++-- lib/matplotlib/pyplot.py | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 doc/api/next_api_changes/2019-08-12-KS.rst diff --git a/doc/api/next_api_changes/2019-08-12-KS.rst b/doc/api/next_api_changes/2019-08-12-KS.rst new file mode 100644 index 000000000000..fbc911d16917 --- /dev/null +++ b/doc/api/next_api_changes/2019-08-12-KS.rst @@ -0,0 +1,8 @@ +Changes in parameter names +`````````````````````````` + +The parameter ``s`` to `.Axes.annotate` and `.pyplot.annotate` is renamed to +``text``, matching `.Annotation`. + +The old parameter name remains supported for `.Axes.annotate`, but +support for it will be dropped in a future Matplotlib release. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index d5546e564933..d85a105ffae0 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -753,9 +753,10 @@ def text(self, x, y, s, fontdict=None, **kwargs): self._add_text(t) return t + @cbook._rename_parameter("3.2", "s", "text") @docstring.dedent_interpd - def annotate(self, s, xy, *args, **kwargs): - a = mtext.Annotation(s, xy, *args, **kwargs) + def annotate(self, text, xy, *args, **kwargs): + a = mtext.Annotation(text, xy, *args, **kwargs) a.set_transform(mtransforms.IdentityTransform()) if 'clip_on' in kwargs: a.set_clip_path(self.patch) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index d8aaabbe32ad..898d4b3f1383 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -2254,8 +2254,8 @@ def angle_spectrum( # Autogenerated by boilerplate.py. Do not edit as changes will be lost. @_copy_docstring_and_deprecators(Axes.annotate) -def annotate(s, xy, *args, **kwargs): - return gca().annotate(s, xy, *args, **kwargs) +def annotate(text, xy, *args, **kwargs): + return gca().annotate(text, xy, *args, **kwargs) # Autogenerated by boilerplate.py. Do not edit as changes will be lost. From 19298c94d7a48ae42d7219c2f952a9fe3f41ec9c Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Tue, 24 Mar 2020 19:43:04 -0500 Subject: [PATCH 2/3] Add test for annotation parameter name change warning Flake8 Match warning to ensure correct one caught, Update version deprecated Flake8 whitespace Simplify test --- lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/tests/test_axes.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index d85a105ffae0..5a1c46d53575 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -753,7 +753,7 @@ def text(self, x, y, s, fontdict=None, **kwargs): self._add_text(t) return t - @cbook._rename_parameter("3.2", "s", "text") + @cbook._rename_parameter("3.3", "s", "text") @docstring.dedent_interpd def annotate(self, text, xy, *args, **kwargs): a = mtext.Annotation(text, xy, *args, **kwargs) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 2c17ffc520b4..ad2585ac37bd 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -435,6 +435,14 @@ def test_basic_annotate(): xytext=(3, 3), textcoords='offset points') +def test_annotate_parameter_warn(): + fig, ax = plt.subplots() + with pytest.warns(MatplotlibDeprecationWarning, + match=r"The \'s\' parameter of annotate\(\) " + "has been renamed \'text\'"): + ax.annotate(s='now named text', xy=(0, 1)) + + @image_comparison(['arrow_simple.png'], remove_text=True) def test_arrow_simple(): # Simple image test for ax.arrow From cbc65ac25ee7d6875413eb0beb7b865c61b04ab4 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Thu, 26 Mar 2020 11:59:54 -0500 Subject: [PATCH 3/3] Move change description to behaviour.rst Remove specification for where the old parameter remains supported This was fixed by merging #15254 --- doc/api/next_api_changes/2019-08-12-KS.rst | 8 -------- doc/api/next_api_changes/behaviour.rst | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 doc/api/next_api_changes/2019-08-12-KS.rst diff --git a/doc/api/next_api_changes/2019-08-12-KS.rst b/doc/api/next_api_changes/2019-08-12-KS.rst deleted file mode 100644 index fbc911d16917..000000000000 --- a/doc/api/next_api_changes/2019-08-12-KS.rst +++ /dev/null @@ -1,8 +0,0 @@ -Changes in parameter names -`````````````````````````` - -The parameter ``s`` to `.Axes.annotate` and `.pyplot.annotate` is renamed to -``text``, matching `.Annotation`. - -The old parameter name remains supported for `.Axes.annotate`, but -support for it will be dropped in a future Matplotlib release. diff --git a/doc/api/next_api_changes/behaviour.rst b/doc/api/next_api_changes/behaviour.rst index 3a8956825de3..ff7fdc3695e4 100644 --- a/doc/api/next_api_changes/behaviour.rst +++ b/doc/api/next_api_changes/behaviour.rst @@ -138,3 +138,12 @@ Calling ax.arrow() will now autoscale the axes. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... because the offset text can rarely be interpreted without tick labels anyways. + +`.Axes.annotate` and `.pyplot.annotate` parameter name changed +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The parameter ``s`` to `.Axes.annotate` and `.pyplot.annotate` is renamed to +``text``, matching `.Annotation`. + +The old parameter name remains supported, but +support for it will be dropped in a future Matplotlib release. +