@@ -1983,110 +1983,132 @@ def draggable(self, state=None, use_blit=False):
1983
1983
1984
1984
1985
1985
class Annotation (Text , _AnnotationBase ):
1986
+ """
1987
+ An `.Annotation` is a `.Text` that can refer to a specific position *xy*.
1988
+ Optionally an arrow pointing from the text to *xy* can be drawn.
1989
+
1990
+ Attributes
1991
+ ----------
1992
+ xy
1993
+ The annotated position.
1994
+ xycoords
1995
+ The coordinate system for *xy*.
1996
+ arrow_patch
1997
+ A `.FancyArrowPatch` to point from *xytext* to *xy*.
1998
+ """
1999
+
1986
2000
def __str__ (self ):
1987
2001
return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
1988
2002
1989
- @docstring .dedent_interpd
1990
2003
def __init__ (self , s , xy ,
1991
2004
xytext = None ,
1992
2005
xycoords = 'data' ,
1993
2006
textcoords = None ,
1994
2007
arrowprops = None ,
1995
2008
annotation_clip = None ,
1996
2009
** kwargs ):
1997
- '''
1998
- Annotate the point ``xy`` with text ``s``.
2010
+ """
2011
+ Annotate the point *xy* with text *s*.
2012
+
2013
+ In the simplest form, the text is placed at *xy*.
1999
2014
2000
- Additional kwargs are passed to `~matplotlib.text.Text`.
2015
+ Optionally, the text can be displayed in another position *xytext*.
2016
+ An arrow pointing from the text to the annotated point *xy* can then
2017
+ be added by defining *arrowprops*.
2001
2018
2002
2019
Parameters
2003
2020
----------
2004
-
2005
2021
s : str
2006
2022
The text of the annotation.
2007
2023
2008
- xy : iterable
2009
- Length 2 sequence specifying the *(x,y)* point to annotate.
2024
+ xy : (float, float)
2025
+ The point *(x,y)* to annotate.
2026
+
2027
+ xytext : (float, float), optional
2028
+ The position *(x,y)* to place the text at.
2029
+ If *None*, defaults to *xy*.
2010
2030
2011
- xytext : iterable, optional
2012
- Length 2 sequence specifying the *(x,y)* to place the text
2013
- at. If None, defaults to ``xy``.
2031
+ xycoords : str, `.Artist`, `.Transform`, callable or tuple, optional
2014
2032
2015
- xycoords : str, Artist, Transform, callable or tuple, optional
2033
+ The coordinate system that *xy* is given in. The following types
2034
+ of values are supported:
2016
2035
2017
- The coordinate system that ``xy`` is given in.
2036
+ - One of the following strings:
2018
2037
2019
- For a `str` the allowed values are:
2038
+ ================= =============================================
2039
+ Value Description
2040
+ ================= =============================================
2041
+ 'figure points' Points from the lower left of the figure
2042
+ 'figure pixels' Pixels from the lower left of the figure
2043
+ 'figure fraction' Fraction of figure from lower left
2044
+ 'axes points' Points from lower left corner of axes
2045
+ 'axes pixels' Pixels from lower left corner of axes
2046
+ 'axes fraction' Fraction of axes from lower left
2047
+ 'data' Use the coordinate system of the object being
2048
+ annotated (default)
2049
+ 'polar' *(theta,r)* if not native 'data' coordinates
2050
+ ================= =============================================
2020
2051
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
- ================= ===============================================
2052
+ - An `.Artist`: *xy* is interpreted as a fraction of the artists
2053
+ `~matplotlib.transforms.Bbox`. E.g. *(0, 0)* would be the lower
2054
+ left corner of the bounding box and *(0.5, 1)* would be the
2055
+ center top of the bounding box.
2034
2056
2035
- If a `~matplotlib.artist.Artist` object is passed in the units are
2036
- fraction if it's bounding box.
2057
+ - A `.Transform` to transform *xy* to screen coordinates.
2037
2058
2038
- If a `~matplotlib.transforms.Transform` object is passed
2039
- in use that to transform ``xy`` to screen coordinates
2059
+ - A function with one of the following signatures::
2040
2060
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
2061
+ def transform(renderer) -> Bbox
2062
+ def transform(renderer) -> Transform
2045
2063
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*.
2064
+ where *renderer* is a `.RendererBase` subclass.
2065
+
2066
+ The result of the function is interpreted like the `.Artist` and
2067
+ `.Transform` cases above.
2068
+
2069
+ - A tuple *(xcoords, ycoords)* specifying separate coordinate
2070
+ systems for *x* and *y*. *xcoords* and *ycoords* must each be
2071
+ of one of the above described types.
2049
2072
2050
2073
See :ref:`plotting-guide-annotation` for more details.
2051
2074
2052
- Defaults to `` 'data'``
2075
+ Defaults to 'data'.
2053
2076
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``.
2077
+ textcoords : str, `.Artist`, `.Transform`, callable or tuple, optional
2078
+ The coordinate system that *xytext* is given in.
2058
2079
2059
- All `` xycoords`` values are valid as well as the following
2080
+ All * xycoords* values are valid as well as the following
2060
2081
strings:
2061
2082
2062
2083
================= =========================================
2063
- Property Description
2084
+ Value Description
2064
2085
================= =========================================
2065
- 'offset points' offset (in points) from the *xy* value
2066
- 'offset pixels' offset (in pixels) from the *xy* value
2086
+ 'offset points' Offset (in points) from the *xy* value
2087
+ 'offset pixels' Offset (in pixels) from the *xy* value
2067
2088
================= =========================================
2068
2089
2069
- defaults to the input of ``xycoords``
2090
+ Defaults to the value of *xycoords*, i.e. use the same coordinate
2091
+ system for annotation point and text position.
2070
2092
2071
2093
arrowprops : dict, optional
2072
- If not None, properties used to draw a
2073
- `~matplotlib.patches.FancyArrowPatch` arrow between ``xy`` and
2074
- `` xytext`` .
2094
+ The properties used to draw a
2095
+ `~matplotlib.patches.FancyArrowPatch` arrow between the
2096
+ positions *xy* and * xytext* .
2075
2097
2076
- If ` arrowprops` does not contain the key `` 'arrowstyle'`` the
2098
+ If * arrowprops* does not contain the key 'arrowstyle' the
2077
2099
allowed keys are:
2078
2100
2079
2101
========== ======================================================
2080
2102
Key Description
2081
2103
========== ======================================================
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`
2104
+ width The width of the arrow in points
2105
+ headwidth The width of the base of the arrow head in points
2106
+ headlength The length of the arrow head in points
2107
+ shrink Fraction of total length to shrink from both ends
2108
+ ? Any key to :class:`matplotlib.patches.FancyArrowPatch`
2087
2109
========== ======================================================
2088
2110
2089
- If the ` arrowprops` contains the key `` 'arrowstyle'`` the
2111
+ If * arrowprops* contains the key 'arrowstyle' the
2090
2112
above keys are forbidden. The allowed values of
2091
2113
``'arrowstyle'`` are:
2092
2114
@@ -2124,25 +2146,32 @@ def __init__(self, s, xy,
2124
2146
? any key for :class:`matplotlib.patches.PathPatch`
2125
2147
=============== ==================================================
2126
2148
2127
- Defaults to None
2149
+ Defaults to None, i.e. no arrow is drawn.
2128
2150
2129
- annotation_clip : bool, optional
2130
- Controls the visibility of the annotation when it goes
2151
+ annotation_clip : bool or None , optional
2152
+ Whether to draw the annotation when the annotation point *xy* is
2131
2153
outside the axes area.
2132
2154
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.
2155
+ - If *True*, the annotation will only be drawn when *xy* is
2156
+ within the axes.
2157
+ - If *False*, the annotation will always be drawn.
2158
+ - If *None*, the annotation will only be drawn when *xy* is
2159
+ within the axes and *xycoords* is 'data'.
2160
+
2161
+ Defaults to *None*.
2136
2162
2137
- The default is `None`, which behave as `True` only if
2138
- *xycoords* is "data" .
2163
+ **kwargs
2164
+ Additional kwargs are passed to `~matplotlib.text.Text` .
2139
2165
2140
2166
Returns
2141
2167
-------
2142
- Annotation
2168
+ annotation : `. Annotation`
2143
2169
2144
- '''
2170
+ See Also
2171
+ --------
2172
+ :ref:`plotting-guide-annotation`.
2145
2173
2174
+ """
2146
2175
_AnnotationBase .__init__ (self ,
2147
2176
xy ,
2148
2177
xycoords = xycoords ,
@@ -2196,6 +2225,11 @@ def contains(self, event):
2196
2225
2197
2226
@property
2198
2227
def xyann (self ):
2228
+ """
2229
+ The the text position.
2230
+
2231
+ See also *xytext* in `.Annotation`.
2232
+ """
2199
2233
return self .get_position ()
2200
2234
2201
2235
@xyann .setter
@@ -2204,14 +2238,26 @@ def xyann(self, xytext):
2204
2238
2205
2239
@property
2206
2240
def anncoords (self ):
2241
+ """The coordinate system to use for `.Annotation.xyann`."""
2207
2242
return self ._textcoords
2208
2243
2209
2244
@anncoords .setter
2210
2245
def anncoords (self , coords ):
2211
2246
self ._textcoords = coords
2212
2247
2213
2248
get_anncoords = anncoords .fget
2249
+ get_anncoords .__doc__ = """
2250
+ Return the coordinate system to use for `.Annotation.xyann`.
2251
+
2252
+ See also *xycoords* in `.Annotation`.
2253
+ """
2254
+
2214
2255
set_anncoords = anncoords .fset
2256
+ set_anncoords .__doc__ = """
2257
+ Set the coordinate system to use for `.Annotation.xyann`.
2258
+
2259
+ See also *xycoords* in `.Annotation`.
2260
+ """
2215
2261
2216
2262
def set_figure (self , fig ):
2217
2263
if self .arrow_patch is not None :
@@ -2386,8 +2432,10 @@ def get_window_extent(self, renderer=None):
2386
2432
return Bbox .union (bboxes )
2387
2433
2388
2434
arrow = property (
2389
- fget = cbook .deprecated ("3.0" )(lambda self : None ),
2390
- fset = cbook .deprecated ("3.0" )(lambda self , value : None ))
2435
+ fget = cbook .deprecated ("3.0" , message = "arrow was deprecated in "
2436
+ "Matplotlib 3.0 and will be removed in 3.2. Use arrow_patch "
2437
+ "instead." )(lambda self : None ),
2438
+ fset = cbook .deprecated ("3.0" , lambda self , value : None ))
2391
2439
2392
2440
2393
2441
docstring .interpd .update (Annotation = Annotation .__init__ .__doc__ )
0 commit comments