@@ -1986,107 +1986,115 @@ class Annotation(Text, _AnnotationBase):
1986
1986
def __str__ (self ):
1987
1987
return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
1988
1988
1989
- @docstring .dedent_interpd
1990
1989
def __init__ (self , s , xy ,
1991
1990
xytext = None ,
1992
1991
xycoords = 'data' ,
1993
1992
textcoords = None ,
1994
1993
arrowprops = None ,
1995
1994
annotation_clip = None ,
1996
1995
** kwargs ):
1997
- '''
1998
- Annotate the point ``xy`` with text ``s`` .
1996
+ """
1997
+ Annotate the point *xy* with text *s* .
1999
1998
2000
- Additional kwargs are passed to `~matplotlib.text.Text`.
1999
+ In the simplest form, the text is placed at *xy*.
2000
+
2001
+ Optionally, the text can be displayed in another position *xytext*.
2002
+ An arrow pointing from the text to the annotated point *xy* can then
2003
+ be added by defining *arrowprops*.
2001
2004
2002
2005
Parameters
2003
2006
----------
2004
-
2005
2007
s : str
2006
2008
The text of the annotation.
2007
2009
2008
- xy : iterable
2009
- Length 2 sequence specifying the *(x,y)* point to annotate.
2010
+ xy : (float, float)
2011
+ The point *(x,y)* to annotate.
2012
+
2013
+ xytext : (float, float), optional
2014
+ The position *(x,y)* to place the text at.
2015
+ If *None*, defaults to *xy*.
2016
+
2017
+ xycoords : str, `.Artist`, `.Transform`, callable or tuple, optional
2010
2018
2011
- xytext : iterable, optional
2012
- Length 2 sequence specifying the *(x,y)* to place the text
2013
- at. If None, defaults to ``xy``.
2019
+ The coordinate system that *xy* is given in. The following types
2020
+ of values are supported:
2014
2021
2015
- xycoords : str, Artist, Transform, callable or tuple, optional
2022
+ - One of the following strings:
2016
2023
2017
- The coordinate system that ``xy`` is given in.
2024
+ ================= =============================================
2025
+ Value Description
2026
+ ================= =============================================
2027
+ 'figure points' Points from the lower left of the figure
2028
+ 'figure pixels' Pixels from the lower left of the figure
2029
+ 'figure fraction' Fraction of figure from lower left
2030
+ 'axes points' Points from lower left corner of axes
2031
+ 'axes pixels' Pixels from lower left corner of axes
2032
+ 'axes fraction' Fraction of axes from lower left
2033
+ 'data' Use the coordinate system of the object being
2034
+ annotated (default)
2035
+ 'polar' *(theta,r)* if not native 'data' coordinates
2036
+ ================= =============================================
2018
2037
2019
- For a `str` the allowed values are:
2038
+ - An `.Artist`: *xy* is interpreted as a fraction of the artists
2039
+ `~matplotlib.transforms.Bbox`. E.g. *(0, 0)* would be the lower
2040
+ left corner of the bounding box and *(0.5, 1)* would be the
2041
+ center top of the bounding box.
2020
2042
2021
- ================= ===============================================
2022
- Property Description
2023
- ================= ===============================================
2024
- 'figure points' points from the lower left of the figure
2025
- 'figure pixels' pixels from the lower left of the figure
2026
- 'figure fraction' fraction of figure from lower left
2027
- 'axes points' points from lower left corner of axes
2028
- 'axes pixels' pixels from lower left corner of axes
2029
- 'axes fraction' fraction of axes from lower left
2030
- 'data' use the coordinate system of the object being
2031
- annotated (default)
2032
- 'polar' *(theta,r)* if not native 'data' coordinates
2033
- ================= ===============================================
2043
+ - A `.Transform` to transform *xy* to screen coordinates.
2034
2044
2035
- If a `~matplotlib.artist.Artist` object is passed in the units are
2036
- fraction if it's bounding box.
2045
+ - A function with one of the following signatures::
2037
2046
2038
- If a `~matplotlib.transforms.Transform` object is passed
2039
- in use that to transform ``xy`` to screen coordinates
2047
+ def transform(renderer) -> Bbox
2048
+ def transform(renderer) -> Transform
2040
2049
2041
- If a callable it must take a
2042
- `~matplotlib.backend_bases.RendererBase` object as input
2043
- and return a `~matplotlib.transforms.Transform` or
2044
- `~matplotlib.transforms.Bbox` object
2050
+ where *renderer* is a `.RendererBase` subclass.
2045
2051
2046
- If a `tuple` must be length 2 tuple of str, `Artist`,
2047
- `Transform` or callable objects. The first transform is
2048
- used for the *x* coordinate and the second for *y*.
2052
+ The result of the function is interpreted like the `.Artist` and
2053
+ `.Transform` cases above.
2054
+
2055
+ - A tuple *(xcoords, ycoords)* specifying separate coordinate
2056
+ systems for *x* and *y*. *xcoords* and *ycoords* must each be
2057
+ of one of the above described types.
2049
2058
2050
2059
See :ref:`plotting-guide-annotation` for more details.
2051
2060
2052
- Defaults to `` 'data'``
2061
+ Defaults to 'data'.
2053
2062
2054
- textcoords : str, `Artist`, `Transform`, callable or tuple, optional
2055
- The coordinate system that ``xytext`` is given, which
2056
- may be different than the coordinate system used for
2057
- ``xy``.
2063
+ textcoords : str, `.Artist`, `.Transform`, callable or tuple, optional
2064
+ The coordinate system that *xytext* is given in.
2058
2065
2059
- All `` xycoords`` values are valid as well as the following
2066
+ All * xycoords* values are valid as well as the following
2060
2067
strings:
2061
2068
2062
2069
================= =========================================
2063
- Property Description
2070
+ Value Description
2064
2071
================= =========================================
2065
- 'offset points' offset (in points) from the *xy* value
2066
- 'offset pixels' offset (in pixels) from the *xy* value
2072
+ 'offset points' Offset (in points) from the *xy* value
2073
+ 'offset pixels' Offset (in pixels) from the *xy* value
2067
2074
================= =========================================
2068
2075
2069
- defaults to the input of ``xycoords``
2076
+ Defaults to the value of *xycoords*, i.e. use the same coordinate
2077
+ system for annotation point and text position.
2070
2078
2071
2079
arrowprops : dict, optional
2072
- If not None, properties used to draw a
2073
- `~matplotlib.patches.FancyArrowPatch` arrow between ``xy`` and
2074
- `` xytext`` .
2080
+ The properties used to draw a
2081
+ `~matplotlib.patches.FancyArrowPatch` arrow between the
2082
+ positions *xy* and * xytext* .
2075
2083
2076
- If ` arrowprops` does not contain the key `` 'arrowstyle'`` the
2084
+ If * arrowprops* does not contain the key 'arrowstyle' the
2077
2085
allowed keys are:
2078
2086
2079
2087
========== ======================================================
2080
2088
Key Description
2081
2089
========== ======================================================
2082
- width the width of the arrow in points
2083
- headwidth the width of the base of the arrow head in points
2084
- headlength the length of the arrow head in points
2085
- shrink fraction of total length to ' shrink' from both ends
2086
- ? any key to :class:`matplotlib.patches.FancyArrowPatch`
2090
+ width The width of the arrow in points
2091
+ headwidth The width of the base of the arrow head in points
2092
+ headlength The length of the arrow head in points
2093
+ shrink Fraction of total length to shrink from both ends
2094
+ ? Any key to :class:`matplotlib.patches.FancyArrowPatch`
2087
2095
========== ======================================================
2088
2096
2089
- If the ` arrowprops` contains the key `` 'arrowstyle'`` the
2097
+ If * arrowprops* contains the key 'arrowstyle' the
2090
2098
above keys are forbidden. The allowed values of
2091
2099
``'arrowstyle'`` are:
2092
2100
@@ -2124,25 +2132,32 @@ def __init__(self, s, xy,
2124
2132
? any key for :class:`matplotlib.patches.PathPatch`
2125
2133
=============== ==================================================
2126
2134
2127
- Defaults to None
2135
+ Defaults to None, i.e. no arrow is drawn.
2128
2136
2129
- annotation_clip : bool, optional
2130
- Controls the visibility of the annotation when it goes
2137
+ annotation_clip : bool or None , optional
2138
+ Whether to draw the annotation when the annotation point *xy* is
2131
2139
outside the axes area.
2132
2140
2133
- If `True`, the annotation will only be drawn when the
2134
- ``xy`` is inside the axes. If `False`, the annotation will
2135
- always be drawn regardless of its position.
2141
+ - If *True*, the annotation will only be drawn when *xy* is
2142
+ within the axes.
2143
+ - If *False*, the annotation will always be drawn.
2144
+ - If *None*, the annotation will only be drawn when *xy* is
2145
+ within the axes and *xycoords* is 'data'.
2146
+
2147
+ Defaults to *None*.
2136
2148
2137
- The default is `None`, which behave as `True` only if
2138
- *xycoords* is "data" .
2149
+ **kwargs
2150
+ Additional kwargs are passed to `~matplotlib.text.Text` .
2139
2151
2140
2152
Returns
2141
2153
-------
2142
- Annotation
2154
+ annotation : `. Annotation`
2143
2155
2144
- '''
2156
+ See Also
2157
+ --------
2158
+ :ref:`plotting-guide-annotation`.
2145
2159
2160
+ """
2146
2161
_AnnotationBase .__init__ (self ,
2147
2162
xy ,
2148
2163
xycoords = xycoords ,
0 commit comments