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

Skip to content

Make signature of Axes.annotate() more explicit. #22388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,13 @@ def text(self, x, y, s, fontdict=None, **kwargs):
return t

@docstring.dedent_interpd
def annotate(self, text, xy, *args, **kwargs):
a = mtext.Annotation(text, xy, *args, **kwargs)
def annotate(self, text, xy, xytext=None, xycoords='data', textcoords=None,
arrowprops=None, annotation_clip=None, **kwargs):
# Signature must match Annotation. This is verified in
# test_annotate_signature().
a = mtext.Annotation(text, xy, xytext=xytext, xycoords=xycoords,
textcoords=textcoords, arrowprops=arrowprops,
annotation_clip=annotation_clip, **kwargs)
a.set_transform(mtransforms.IdentityTransform())
if 'clip_on' in kwargs:
a.set_clip_path(self.patch)
Expand Down
9 changes: 7 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2334,8 +2334,13 @@ def angle_spectrum(

# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.annotate)
def annotate(text, xy, *args, **kwargs):
return gca().annotate(text, xy, *args, **kwargs)
def annotate(
text, xy, xytext=None, xycoords='data', textcoords=None,
arrowprops=None, annotation_clip=None, **kwargs):
return gca().annotate(
text, xy, xytext=xytext, xycoords=xycoords,
textcoords=textcoords, arrowprops=arrowprops,
annotation_clip=annotation_clip, **kwargs)


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
from decimal import Decimal
from functools import partial
import inspect
import io
from itertools import product
import platform
Expand All @@ -26,6 +27,7 @@
import matplotlib.patches as mpatches
import matplotlib.path as mpath
import matplotlib.pyplot as plt
import matplotlib.text as mtext
import matplotlib.ticker as mticker
import matplotlib.transforms as mtransforms
from numpy.testing import (
Expand Down Expand Up @@ -622,6 +624,16 @@ def test_annotate_default_arrow():
assert ann.arrow_patch is not None


def test_annotate_signature():
"""Check that the signature of Axes.annotate() matches Annotation."""
fig, ax = plt.subplots()
annotate_params = inspect.signature(ax.annotate).parameters
annotation_params = inspect.signature(mtext.Annotation).parameters
assert list(annotate_params.keys()) == list(annotation_params.keys())
for p1, p2 in zip(annotate_params.values(), annotation_params.values()):
assert p1 == p2


@image_comparison(['fill_units.png'], savefig_kwarg={'dpi': 60})
def test_fill_units():
import matplotlib.testing.jpl_units as units
Expand Down