@@ -1950,110 +1950,132 @@ def draggable(self, state=None, use_blit=False):
1950
1950
1951
1951
1952
1952
class Annotation (Text , _AnnotationBase ):
1953
+ """
1954
+ An `.Annotation` is a `.Text` that can refer to a specific position *xy*.
1955
+ Optionally an arrow pointing from the text to *xy* can be drawn.
1956
+
1957
+ Attributes
1958
+ ----------
1959
+ xy
1960
+ The annotated position.
1961
+ xycoords
1962
+ The coordinate system for *xy*.
1963
+ arrow_patch
1964
+ A `.FancyArrowPatch` to point from *xytext* to *xy*.
1965
+ """
1966
+
1953
1967
def __str__ (self ):
1954
1968
return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
1955
1969
1956
- @docstring .dedent_interpd
1957
1970
def __init__ (self , s , xy ,
1958
1971
xytext = None ,
1959
1972
xycoords = 'data' ,
1960
1973
textcoords = None ,
1961
1974
arrowprops = None ,
1962
1975
annotation_clip = None ,
1963
1976
** kwargs ):
1964
- '''
1965
- Annotate the point ``xy`` with text ``s``.
1977
+ """
1978
+ Annotate the point *xy* with text *s*.
1979
+
1980
+ In the simplest form, the text is placed at *xy*.
1966
1981
1967
- Additional kwargs are passed to `~matplotlib.text.Text`.
1982
+ Optionally, the text can be displayed in another position *xytext*.
1983
+ An arrow pointing from the text to the annotated point *xy* can then
1984
+ be added by defining *arrowprops*.
1968
1985
1969
1986
Parameters
1970
1987
----------
1971
-
1972
1988
s : str
1973
1989
The text of the annotation.
1974
1990
1975
- xy : iterable
1976
- Length 2 sequence specifying the *(x,y)* point to annotate.
1991
+ xy : (float, float)
1992
+ The point *(x,y)* to annotate.
1993
+
1994
+ xytext : (float, float), optional
1995
+ The position *(x,y)* to place the text at.
1996
+ If *None*, defaults to *xy*.
1977
1997
1978
- xytext : iterable, optional
1979
- Length 2 sequence specifying the *(x,y)* to place the text
1980
- at. If None, defaults to ``xy``.
1998
+ xycoords : str, `.Artist`, `.Transform`, callable or tuple, optional
1981
1999
1982
- xycoords : str, Artist, Transform, callable or tuple, optional
2000
+ The coordinate system that *xy* is given in. The following types
2001
+ of values are supported:
1983
2002
1984
- The coordinate system that ``xy`` is given in.
2003
+ - One of the following strings:
1985
2004
1986
- For a `str` the allowed values are:
2005
+ ================= =============================================
2006
+ Value Description
2007
+ ================= =============================================
2008
+ 'figure points' Points from the lower left of the figure
2009
+ 'figure pixels' Pixels from the lower left of the figure
2010
+ 'figure fraction' Fraction of figure from lower left
2011
+ 'axes points' Points from lower left corner of axes
2012
+ 'axes pixels' Pixels from lower left corner of axes
2013
+ 'axes fraction' Fraction of axes from lower left
2014
+ 'data' Use the coordinate system of the object being
2015
+ annotated (default)
2016
+ 'polar' *(theta,r)* if not native 'data' coordinates
2017
+ ================= =============================================
1987
2018
1988
- ================= ===============================================
1989
- Property Description
1990
- ================= ===============================================
1991
- 'figure points' points from the lower left of the figure
1992
- 'figure pixels' pixels from the lower left of the figure
1993
- 'figure fraction' fraction of figure from lower left
1994
- 'axes points' points from lower left corner of axes
1995
- 'axes pixels' pixels from lower left corner of axes
1996
- 'axes fraction' fraction of axes from lower left
1997
- 'data' use the coordinate system of the object being
1998
- annotated (default)
1999
- 'polar' *(theta,r)* if not native 'data' coordinates
2000
- ================= ===============================================
2019
+ - An `.Artist`: *xy* is interpreted as a fraction of the artists
2020
+ `~matplotlib.transforms.Bbox`. E.g. *(0, 0)* would be the lower
2021
+ left corner of the bounding box and *(0.5, 1)* would be the
2022
+ center top of the bounding box.
2001
2023
2002
- If a `~matplotlib.artist.Artist` object is passed in the units are
2003
- fraction if it's bounding box.
2024
+ - A `.Transform` to transform *xy* to screen coordinates.
2004
2025
2005
- If a `~matplotlib.transforms.Transform` object is passed
2006
- in use that to transform ``xy`` to screen coordinates
2026
+ - A function with one of the following signatures::
2007
2027
2008
- If a callable it must take a
2009
- `~matplotlib.backend_bases.RendererBase` object as input
2010
- and return a `~matplotlib.transforms.Transform` or
2011
- `~matplotlib.transforms.Bbox` object
2028
+ def transform(renderer) -> Bbox
2029
+ def transform(renderer) -> Transform
2012
2030
2013
- If a `tuple` must be length 2 tuple of str, `Artist`,
2014
- `Transform` or callable objects. The first transform is
2015
- used for the *x* coordinate and the second for *y*.
2031
+ where *renderer* is a `.RendererBase` subclass.
2032
+
2033
+ The result of the function is interpreted like the `.Artist` and
2034
+ `.Transform` cases above.
2035
+
2036
+ - A tuple *(xcoords, ycoords)* specifying separate coordinate
2037
+ systems for *x* and *y*. *xcoords* and *ycoords* must each be
2038
+ of one of the above described types.
2016
2039
2017
2040
See :ref:`plotting-guide-annotation` for more details.
2018
2041
2019
- Defaults to `` 'data'``
2042
+ Defaults to 'data'.
2020
2043
2021
- textcoords : str, `Artist`, `Transform`, callable or tuple, optional
2022
- The coordinate system that ``xytext`` is given, which
2023
- may be different than the coordinate system used for
2024
- ``xy``.
2044
+ textcoords : str, `.Artist`, `.Transform`, callable or tuple, optional
2045
+ The coordinate system that *xytext* is given in.
2025
2046
2026
- All `` xycoords`` values are valid as well as the following
2047
+ All * xycoords* values are valid as well as the following
2027
2048
strings:
2028
2049
2029
2050
================= =========================================
2030
- Property Description
2051
+ Value Description
2031
2052
================= =========================================
2032
- 'offset points' offset (in points) from the *xy* value
2033
- 'offset pixels' offset (in pixels) from the *xy* value
2053
+ 'offset points' Offset (in points) from the *xy* value
2054
+ 'offset pixels' Offset (in pixels) from the *xy* value
2034
2055
================= =========================================
2035
2056
2036
- defaults to the input of ``xycoords``
2057
+ Defaults to the value of *xycoords*, i.e. use the same coordinate
2058
+ system for annotation point and text position.
2037
2059
2038
2060
arrowprops : dict, optional
2039
- If not None, properties used to draw a
2040
- `~matplotlib.patches.FancyArrowPatch` arrow between ``xy`` and
2041
- `` xytext`` .
2061
+ The properties used to draw a
2062
+ `~matplotlib.patches.FancyArrowPatch` arrow between the
2063
+ positions *xy* and * xytext* .
2042
2064
2043
- If ` arrowprops` does not contain the key `` 'arrowstyle'`` the
2065
+ If * arrowprops* does not contain the key 'arrowstyle' the
2044
2066
allowed keys are:
2045
2067
2046
2068
========== ======================================================
2047
2069
Key Description
2048
2070
========== ======================================================
2049
- width the width of the arrow in points
2050
- headwidth the width of the base of the arrow head in points
2051
- headlength the length of the arrow head in points
2052
- shrink fraction of total length to ' shrink' from both ends
2053
- ? any key to :class:`matplotlib.patches.FancyArrowPatch`
2071
+ width The width of the arrow in points
2072
+ headwidth The width of the base of the arrow head in points
2073
+ headlength The length of the arrow head in points
2074
+ shrink Fraction of total length to shrink from both ends
2075
+ ? Any key to :class:`matplotlib.patches.FancyArrowPatch`
2054
2076
========== ======================================================
2055
2077
2056
- If the ` arrowprops` contains the key `` 'arrowstyle'`` the
2078
+ If * arrowprops* contains the key 'arrowstyle' the
2057
2079
above keys are forbidden. The allowed values of
2058
2080
``'arrowstyle'`` are:
2059
2081
@@ -2091,25 +2113,32 @@ def __init__(self, s, xy,
2091
2113
? any key for :class:`matplotlib.patches.PathPatch`
2092
2114
=============== ==================================================
2093
2115
2094
- Defaults to None
2116
+ Defaults to None, i.e. no arrow is drawn.
2095
2117
2096
- annotation_clip : bool, optional
2097
- Controls the visibility of the annotation when it goes
2118
+ annotation_clip : bool or None , optional
2119
+ Whether to draw the annotation when the annotation point *xy* is
2098
2120
outside the axes area.
2099
2121
2100
- If `True`, the annotation will only be drawn when the
2101
- ``xy`` is inside the axes. If `False`, the annotation will
2102
- always be drawn regardless of its position.
2122
+ - If *True*, the annotation will only be drawn when *xy* is
2123
+ within the axes.
2124
+ - If *False*, the annotation will always be drawn.
2125
+ - If *None*, the annotation will only be drawn when *xy* is
2126
+ within the axes and *xycoords* is 'data'.
2127
+
2128
+ Defaults to *None*.
2103
2129
2104
- The default is `None`, which behave as `True` only if
2105
- *xycoords* is "data" .
2130
+ **kwargs
2131
+ Additional kwargs are passed to `~matplotlib.text.Text` .
2106
2132
2107
2133
Returns
2108
2134
-------
2109
- Annotation
2135
+ annotation : `. Annotation`
2110
2136
2111
- '''
2137
+ See Also
2138
+ --------
2139
+ :ref:`plotting-guide-annotation`.
2112
2140
2141
+ """
2113
2142
_AnnotationBase .__init__ (self ,
2114
2143
xy ,
2115
2144
xycoords = xycoords ,
@@ -2163,6 +2192,11 @@ def contains(self, event):
2163
2192
2164
2193
@property
2165
2194
def xyann (self ):
2195
+ """
2196
+ The the text position.
2197
+
2198
+ See also *xytext* in `.Annotation`.
2199
+ """
2166
2200
return self .get_position ()
2167
2201
2168
2202
@xyann .setter
@@ -2171,14 +2205,26 @@ def xyann(self, xytext):
2171
2205
2172
2206
@property
2173
2207
def anncoords (self ):
2208
+ """The coordinate system to use for `.Annotation.xyann`."""
2174
2209
return self ._textcoords
2175
2210
2176
2211
@anncoords .setter
2177
2212
def anncoords (self , coords ):
2178
2213
self ._textcoords = coords
2179
2214
2180
2215
get_anncoords = anncoords .fget
2216
+ get_anncoords .__doc__ = """
2217
+ Return the coordinate system to use for `.Annotation.xyann`.
2218
+
2219
+ See also *xycoords* in `.Annotation`.
2220
+ """
2221
+
2181
2222
set_anncoords = anncoords .fset
2223
+ set_anncoords .__doc__ = """
2224
+ Set the coordinate system to use for `.Annotation.xyann`.
2225
+
2226
+ See also *xycoords* in `.Annotation`.
2227
+ """
2182
2228
2183
2229
def set_figure (self , fig ):
2184
2230
if self .arrow_patch is not None :
@@ -2353,7 +2399,9 @@ def get_window_extent(self, renderer=None):
2353
2399
return Bbox .union (bboxes )
2354
2400
2355
2401
arrow = property (
2356
- fget = cbook .deprecated ("3.0" )(lambda self : None ),
2402
+ fget = cbook .deprecated ("3.0" , message = "arrow was deprecated in "
2403
+ "Matplotlib 3.0 and will be removed in 3.2. Use arrow_patch "
2404
+ "instead." )(lambda self : None ),
2357
2405
fset = cbook .deprecated ("3.0" )(lambda self , value : None ))
2358
2406
2359
2407
0 commit comments