@@ -1978,110 +1978,132 @@ def draggable(self, state=None, use_blit=False):
19781978
19791979
19801980class Annotation (Text , _AnnotationBase ):
1981+ """
1982+ An `.Annotation` is a `.Text` that can refer to a specific position *xy*.
1983+ Optionally an arrow pointing from the text to *xy* can be drawn.
1984+
1985+ Attributes
1986+ ----------
1987+ xy
1988+ The annotated position.
1989+ xycoords
1990+ The coordinate system for *xy*.
1991+ arrow_patch
1992+ A `.FancyArrowPatch` to point from *xytext* to *xy*.
1993+ """
1994+
19811995 def __str__ (self ):
19821996 return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
19831997
1984- @docstring .dedent_interpd
19851998 def __init__ (self , s , xy ,
19861999 xytext = None ,
19872000 xycoords = 'data' ,
19882001 textcoords = None ,
19892002 arrowprops = None ,
19902003 annotation_clip = None ,
19912004 ** kwargs ):
1992- '''
1993- Annotate the point ``xy`` with text ``s``.
2005+ """
2006+ Annotate the point *xy* with text *s*.
2007+
2008+ In the simplest form, the text is placed at *xy*.
19942009
1995- Additional kwargs are passed to `~matplotlib.text.Text`.
2010+ Optionally, the text can be displayed in another position *xytext*.
2011+ An arrow pointing from the text to the annotated point *xy* can then
2012+ be added by defining *arrowprops*.
19962013
19972014 Parameters
19982015 ----------
1999-
20002016 s : str
20012017 The text of the annotation.
20022018
2003- xy : iterable
2004- Length 2 sequence specifying the *(x,y)* point to annotate.
2019+ xy : (float, float)
2020+ The point *(x,y)* to annotate.
2021+
2022+ xytext : (float, float), optional
2023+ The position *(x,y)* to place the text at.
2024+ If *None*, defaults to *xy*.
2025+
2026+ xycoords : str, `.Artist`, `.Transform`, callable or tuple, optional
20052027
2006- xytext : iterable, optional
2007- Length 2 sequence specifying the *(x,y)* to place the text
2008- at. If None, defaults to ``xy``.
2028+ The coordinate system that *xy* is given in. The following types
2029+ of values are supported:
20092030
2010- xycoords : str, Artist, Transform, callable or tuple, optional
2031+ - One of the following strings:
20112032
2012- The coordinate system that ``xy`` is given in.
2033+ ================= =============================================
2034+ Value Description
2035+ ================= =============================================
2036+ 'figure points' Points from the lower left of the figure
2037+ 'figure pixels' Pixels from the lower left of the figure
2038+ 'figure fraction' Fraction of figure from lower left
2039+ 'axes points' Points from lower left corner of axes
2040+ 'axes pixels' Pixels from lower left corner of axes
2041+ 'axes fraction' Fraction of axes from lower left
2042+ 'data' Use the coordinate system of the object being
2043+ annotated (default)
2044+ 'polar' *(theta,r)* if not native 'data' coordinates
2045+ ================= =============================================
20132046
2014- For a `str` the allowed values are:
2047+ - An `.Artist`: *xy* is interpreted as a fraction of the artists
2048+ `~matplotlib.transforms.Bbox`. E.g. *(0, 0)* would be the lower
2049+ left corner of the bounding box and *(0.5, 1)* would be the
2050+ center top of the bounding box.
20152051
2016- ================= ===============================================
2017- Property Description
2018- ================= ===============================================
2019- 'figure points' points from the lower left of the figure
2020- 'figure pixels' pixels from the lower left of the figure
2021- 'figure fraction' fraction of figure from lower left
2022- 'axes points' points from lower left corner of axes
2023- 'axes pixels' pixels from lower left corner of axes
2024- 'axes fraction' fraction of axes from lower left
2025- 'data' use the coordinate system of the object being
2026- annotated (default)
2027- 'polar' *(theta,r)* if not native 'data' coordinates
2028- ================= ===============================================
2052+ - A `.Transform` to transform *xy* to screen coordinates.
20292053
2030- If a `~matplotlib.artist.Artist` object is passed in the units are
2031- fraction if it's bounding box.
2054+ - A function with one of the following signatures::
20322055
2033- If a `~matplotlib.transforms.Transform` object is passed
2034- in use that to transform ``xy`` to screen coordinates
2056+ def transform(renderer) -> Bbox
2057+ def transform(renderer) -> Transform
20352058
2036- If a callable it must take a
2037- `~matplotlib.backend_bases.RendererBase` object as input
2038- and return a `~matplotlib.transforms.Transform` or
2039- `~matplotlib.transforms.Bbox` object
2059+ where *renderer* is a `.RendererBase` subclass.
20402060
2041- If a `tuple` must be length 2 tuple of str, `Artist`,
2042- `Transform` or callable objects. The first transform is
2043- used for the *x* coordinate and the second for *y*.
2061+ The result of the function is interpreted like the `.Artist` and
2062+ `.Transform` cases above.
2063+
2064+ - A tuple *(xcoords, ycoords)* specifying separate coordinate
2065+ systems for *x* and *y*. *xcoords* and *ycoords* must each be
2066+ of one of the above described types.
20442067
20452068 See :ref:`plotting-guide-annotation` for more details.
20462069
2047- Defaults to `` 'data'``
2070+ Defaults to 'data'.
20482071
2049- textcoords : str, `Artist`, `Transform`, callable or tuple, optional
2050- The coordinate system that ``xytext`` is given, which
2051- may be different than the coordinate system used for
2052- ``xy``.
2072+ textcoords : str, `.Artist`, `.Transform`, callable or tuple, optional
2073+ The coordinate system that *xytext* is given in.
20532074
2054- All `` xycoords`` values are valid as well as the following
2075+ All * xycoords* values are valid as well as the following
20552076 strings:
20562077
20572078 ================= =========================================
2058- Property Description
2079+ Value Description
20592080 ================= =========================================
2060- 'offset points' offset (in points) from the *xy* value
2061- 'offset pixels' offset (in pixels) from the *xy* value
2081+ 'offset points' Offset (in points) from the *xy* value
2082+ 'offset pixels' Offset (in pixels) from the *xy* value
20622083 ================= =========================================
20632084
2064- defaults to the input of ``xycoords``
2085+ Defaults to the value of *xycoords*, i.e. use the same coordinate
2086+ system for annotation point and text position.
20652087
20662088 arrowprops : dict, optional
2067- If not None, properties used to draw a
2068- `~matplotlib.patches.FancyArrowPatch` arrow between ``xy`` and
2069- `` xytext`` .
2089+ The properties used to draw a
2090+ `~matplotlib.patches.FancyArrowPatch` arrow between the
2091+ positions *xy* and * xytext* .
20702092
2071- If ` arrowprops` does not contain the key `` 'arrowstyle'`` the
2093+ If * arrowprops* does not contain the key 'arrowstyle' the
20722094 allowed keys are:
20732095
20742096 ========== ======================================================
20752097 Key Description
20762098 ========== ======================================================
2077- width the width of the arrow in points
2078- headwidth the width of the base of the arrow head in points
2079- headlength the length of the arrow head in points
2080- shrink fraction of total length to ' shrink' from both ends
2081- ? any key to :class:`matplotlib.patches.FancyArrowPatch`
2099+ width The width of the arrow in points
2100+ headwidth The width of the base of the arrow head in points
2101+ headlength The length of the arrow head in points
2102+ shrink Fraction of total length to shrink from both ends
2103+ ? Any key to :class:`matplotlib.patches.FancyArrowPatch`
20822104 ========== ======================================================
20832105
2084- If the ` arrowprops` contains the key `` 'arrowstyle'`` the
2106+ If * arrowprops* contains the key 'arrowstyle' the
20852107 above keys are forbidden. The allowed values of
20862108 ``'arrowstyle'`` are:
20872109
@@ -2119,25 +2141,32 @@ def __init__(self, s, xy,
21192141 ? any key for :class:`matplotlib.patches.PathPatch`
21202142 =============== ==================================================
21212143
2122- Defaults to None
2144+ Defaults to None, i.e. no arrow is drawn.
21232145
2124- annotation_clip : bool, optional
2125- Controls the visibility of the annotation when it goes
2146+ annotation_clip : bool or None , optional
2147+ Whether to draw the annotation when the annotation point *xy* is
21262148 outside the axes area.
21272149
2128- If `True`, the annotation will only be drawn when the
2129- ``xy`` is inside the axes. If `False`, the annotation will
2130- always be drawn regardless of its position.
2150+ - If *True*, the annotation will only be drawn when *xy* is
2151+ within the axes.
2152+ - If *False*, the annotation will always be drawn.
2153+ - If *None*, the annotation will only be drawn when *xy* is
2154+ within the axes and *xycoords* is 'data'.
2155+
2156+ Defaults to *None*.
21312157
2132- The default is `None`, which behave as `True` only if
2133- *xycoords* is "data" .
2158+ **kwargs
2159+ Additional kwargs are passed to `~matplotlib.text.Text` .
21342160
21352161 Returns
21362162 -------
2137- Annotation
2163+ annotation : `. Annotation`
21382164
2139- '''
2165+ See Also
2166+ --------
2167+ :ref:`plotting-guide-annotation`.
21402168
2169+ """
21412170 _AnnotationBase .__init__ (self ,
21422171 xy ,
21432172 xycoords = xycoords ,
@@ -2191,6 +2220,11 @@ def contains(self, event):
21912220
21922221 @property
21932222 def xyann (self ):
2223+ """
2224+ The the text position.
2225+
2226+ See also *xytext* in `.Annotation`.
2227+ """
21942228 return self .get_position ()
21952229
21962230 @xyann .setter
@@ -2199,12 +2233,27 @@ def xyann(self, xytext):
21992233
22002234 @property
22012235 def anncoords (self ):
2236+ """The coordinate system to use for `.Annotation.xyann`."""
22022237 return self ._textcoords
22032238
22042239 @anncoords .setter
22052240 def anncoords (self , coords ):
22062241 self ._textcoords = coords
22072242
2243+ get_anncoords = anncoords .fget
2244+ get_anncoords .__doc__ = """
2245+ Return the coordinate system to use for `.Annotation.xyann`.
2246+
2247+ See also *xycoords* in `.Annotation`.
2248+ """
2249+
2250+ set_anncoords = anncoords .fset
2251+ set_anncoords .__doc__ = """
2252+ Set the coordinate system to use for `.Annotation.xyann`.
2253+
2254+ See also *xycoords* in `.Annotation`.
2255+ """
2256+
22082257 def set_figure (self , fig ):
22092258 if self .arrow_patch is not None :
22102259 self .arrow_patch .set_figure (fig )
@@ -2378,7 +2427,9 @@ def get_window_extent(self, renderer=None):
23782427 return Bbox .union (bboxes )
23792428
23802429 arrow = property (
2381- fget = cbook .deprecated ("3.0" )(lambda self : None ),
2430+ fget = cbook .deprecated ("3.0" , message = "arrow was deprecated in "
2431+ "Matplotlib 3.0 and will be removed in 3.2. Use arrow_patch "
2432+ "instead." )(lambda self : None ),
23822433 fset = cbook .deprecated ("3.0" )(lambda self , value : None ))
23832434
23842435
0 commit comments