8000 Merge pull request #15988 from anntzer/annprops · matplotlib/matplotlib@90fb532 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90fb532

Browse files
authored
Merge pull request #15988 from anntzer/annprops
Refactor Annotation properties.
2 parents 07a108f + f81b068 commit 90fb532

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

lib/matplotlib/text.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,19 +1464,10 @@ def _get_xy_transform(self, renderer, s):
14641464

14651465
def _get_ref_xy(self, renderer):
14661466
"""
1467-
Return x, y (in display coordinate) that is to be used for a reference
1467+
Return x, y (in display coordinates) that is to be used for a reference
14681468
of any offset coordinate.
14691469
"""
1470-
def is_offset(s):
1471-
return isinstance(s, str) and s.split()[0] == "offset"
1472-
1473-
if isinstance(self.xycoords, tuple):
1474-
if any(map(is_offset, self.xycoords)):
1475-
raise ValueError("xycoords should not be an offset coordinate")
1476-
elif is_offset(self.xycoords):
1477-
raise ValueError("xycoords should not be an offset coordinate")
1478-
x, y = self.xy
1479-
return self._get_xy(renderer, x, y, self.xycoords)
1470+
return self._get_xy(renderer, *self.xy, self.xycoords)
14801471

14811472
# def _get_bbox(self, renderer):
14821473
# if hasattr(bbox, "bounds"):
@@ -1798,10 +1789,24 @@ def contains(self, event):
17981789
contains = contains or in_patch
17991790
return contains, tinfo
18001791

1792+
@property
1793+
def xycoords(self):
1794+
return self._xycoords
1795+
1796+
@xycoords.setter
1797+
def xycoords(self, xycoords):
1798+
def is_offset(s):
1799+
return isinstance(s, str) and s.startswith("offset")
1800+
1801+
if (isinstance(xycoords, tuple) and any(map(is_offset, xycoords))
1802+
or is_offset(xycoords)):
1803+
raise ValueError("xycoords cannot be an offset coordinate")
1804+
self._xycoords = xycoords
1805+
18011806
@property
18021807
def xyann(self):
18031808
"""
1804-
The the text position.
1809+
The text position.
18051810
18061811
See also *xytext* in `.Annotation`.
18071812
"""
@@ -1811,28 +1816,24 @@ def xyann(self):
18111816
def xyann(self, xytext):
18121817
self.set_position(xytext)
18131818

1814-
@property
1815-
def anncoords(self):
1816-
"""The coordinate system to use for `.Annotation.xyann`."""
1817-
return self._textcoords
1818-
1819-
@anncoords.setter
1820-
def anncoords(self, coords):
1821-
self._textcoords = coords
1819+
def get_anncoords(self):
1820+
"""
1821+
Return the coordinate system to use for `.Annotation.xyann`.
18221822
1823-
get_anncoords = anncoords.fget
1824-
get_anncoords.__doc__ = """
1825-
Return the coordinate system to use for `.Annotation.xyann`.
1823+
See also *xycoords* in `.Annotation`.
1824+
"""
1825+
return self._textcoords
18261826

1827-
See also *xycoords* in `.Annotation`.
1828-
"""
1827+
def set_anncoords(self, coords):
1828+
"""
1829+
Set the coordinate system to use for `.Annotation.xyann`.
18291830
1830-
set_anncoords = anncoords.fset
1831-
set_anncoords.__doc__ = """
1832-
Set the coordinate system to use for `.Annotation.xyann`.
1831+
See also *xycoords* in `.Annotation`.
1832+
"""
1833+
self._textcoords = coords
18331834

1834-
See also *xycoords* in `.Annotation`.
1835-
"""
1835+
anncoords = property(get_anncoords, set_anncoords, doc="""
1836+
The coordinate system to use for `.Annotation.xyann`.""")
18361837

18371838
def set_figure(self, fig):
18381839
# docstring inherited

0 commit comments

Comments
 (0)
0