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

Skip to content

Commit a032c6f

Browse files
authored
Merge pull request #15049 from ksunden/annotate_argument
Annotate argument in axes class match upstream
2 parents 5713554 + cbc65ac commit a032c6f

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,12 @@ Calling ax.arrow() will now autoscale the axes.
138138
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139139
... because the offset text can rarely be interpreted without tick labels
140140
anyways.
141+
142+
`.Axes.annotate` and `.pyplot.annotate` parameter name changed
143+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144+
The parameter ``s`` to `.Axes.annotate` and `.pyplot.annotate` is renamed to
145+
``text``, matching `.Annotation`.
146+
147+
The old parameter name remains supported, but
148+
support for it will be dropped in a future Matplotlib release.
149+

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,10 @@ def text(self, x, y, s, fontdict=None, **kwargs):
753753
self._add_text(t)
754754
return t
755755

756+
@cbook._rename_parameter("3.3", "s", "text")
756757
@docstring.dedent_interpd
757-
def annotate(self, s, xy, *args, **kwargs):
758-
a = mtext.Annotation(s, xy, *args, **kwargs)
758+
def annotate(self, text, xy, *args, **kwargs):
759+
a = mtext.Annotation(text, xy, *args, **kwargs)
759760
a.set_transform(mtransforms.IdentityTransform())
760761
if 'clip_on' in kwargs:
761762
a.set_clip_path(self.patch)

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,8 +2254,8 @@ def angle_spectrum(
22542254

22552255
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
22562256
@_copy_docstring_and_deprecators(Axes.annotate)
2257-
def annotate(s, xy, *args, **kwargs):
2258-
return gca().annotate(s, xy, *args, **kwargs)
2257+
def annotate(text, xy, *args, **kwargs):
2258+
return gca().annotate(text, xy, *args, **kwargs)
22592259

22602260

22612261
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ def test_basic_annotate():
435435
xytext=(3, 3), textcoords='offset points')
436436

437437

438+
def test_annotate_parameter_warn():
439+
fig, ax = plt.subplots()
440+
with pytest.warns(MatplotlibDeprecationWarning,
441+
match=r"The \'s\' parameter of annotate\(\) "
442+
"has been renamed \'text\'"):
443+
ax.annotate(s='now named text', xy=(0, 1))
444+
445+
438446
@image_comparison(['arrow_simple.png'], remove_text=True)
439447
def test_arrow_simple():
440448
# Simple image test for ax.arrow

0 commit comments

Comments
 (0)