@@ -1978,110 +1978,132 @@ def draggable(self, state=None, use_blit=False):
1978
1978
1979
1979
1980
1980
class 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
+
1981
1995
def __str__ (self ):
1982
1996
return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
1983
1997
1984
- @docstring .dedent_interpd
1985
1998
def __init__ (self , s , xy ,
1986
1999
xytext = None ,
1987
2000
xycoords = 'data' ,
1988
2001
textcoords = None ,
1989
2002
arrowprops = None ,
1990
2003
annotation_clip = None ,
1991
2004
** 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*.
1994
2009
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*.
1996
2013
1997
2014
Parameters
1998
2015
----------
1999
-
2000
2016
s : str
2001
2017
The text of the annotation.
2002
2018
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
2005
2027
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:
2009
2030
2010
- xycoords : str, Artist, Transform, callable or tuple, optional
2031
+ - One of the following strings:
2011
2032
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
+ ================= =============================================
2013
2046
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.
2015
2051
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.
2029
2053
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::
2032
2055
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
2035
2058
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.
2040
2060
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.
2044
2067
2045
2068
See :ref:`plotting-guide-annotation` for more details.
2046
2069
2047
- Defaults to `` 'data'``
2070
+ Defaults to 'data'.
2048
2071
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.
2053
2074
2054
- All `` xycoords`` values are valid as well as the following
2075
+ All * xycoords* values are valid as well as the following
2055
2076
strings:
2056
2077
2057
2078
================= =========================================
2058
- Property Description
2079
+ Value Description
2059
2080
================= =========================================
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
2062
2083
================= =========================================
2063
2084
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.
2065
2087
2066
2088
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* .
2070
2092
2071
- If ` arrowprops` does not contain the key `` 'arrowstyle'`` the
2093
+ If * arrowprops* does not contain the key 'arrowstyle' the
2072
2094
allowed keys are:
2073
2095
2074
2096
========== ======================================================
2075
2097
Key Description
2076
2098
========== ======================================================
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`
2082
2104
========== ======================================================
2083
2105
2084
- If the ` arrowprops` contains the key `` 'arrowstyle'`` the
2106
+ If * arrowprops* contains the key 'arrowstyle' the
2085
2107
above keys are forbidden. The allowed values of
2086
2108
``'arrowstyle'`` are:
2087
2109
@@ -2119,25 +2141,32 @@ def __init__(self, s, xy,
2119
2141
? any key for :class:`matplotlib.patches.PathPatch`
2120
2142
=============== ==================================================
2121
2143
2122
- Defaults to None
2144
+ Defaults to None, i.e. no arrow is drawn.
2123
2145
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
2126
2148
outside the axes area.
2127
2149
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*.
2131
2157
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` .
2134
2160
2135
2161
Returns
2136
2162
-------
2137
- Annotation
2163
+ annotation : `. Annotation`
2138
2164
2139
- '''
2165
+ See Also
2166
+ --------
2167
+ :ref:`plotting-guide-annotation`.
2140
2168
2169
+ """
2141
2170
_AnnotationBase .__init__ (self ,
2142
2171
xy ,
2143
2172
xycoords = xycoords ,
@@ -2191,6 +2220,11 @@ def contains(self, event):
2191
2220
2192
2221
@property
2193
2222
def xyann (self ):
2223
+ """
2224
+ The the text position.
2225
+
2226
+ See also *xytext* in `.Annotation`.
2227
+ """
2194
2228
return self .get_position ()
2195
2229
2196
2230
@xyann .setter
@@ -2199,12 +2233,27 @@ def xyann(self, xytext):
2199
2233
2200
2234
@property
2201
2235
def anncoords (self ):
2236
+ """The coordinate system to use for `.Annotation.xyann`."""
2202
2237
return self ._textcoords
2203
2238
2204
2239
@anncoords .setter
2205
2240
def anncoords (self , coords ):
2206
2241
self ._textcoords = coords
2207
2242
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
+
2208
2257
def set_figure (self , fig ):
2209
2258
if self .arrow_patch is not None :
2210
2259
self .arrow_patch .set_figure (fig )
@@ -2378,7 +2427,9 @@ def get_window_extent(self, renderer=None):
2378
2427
return Bbox .union (bboxes )
2379
2428
2380
2429
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 ),
2382
2433
fset = cbook .deprecated ("3.0" )(lambda self , value : None ))
2383
2434
2384
2435
0 commit comments