@@ -1667,9 +1667,10 @@ def set_figure(self, fig):
1667
1667
1668
1668
1669
1669
class OffsetFrom :
1670
- 'Callable helper class for working with `Annotation`'
1670
+ """Callable helper class for working with `Annotation`."""
1671
+
1671
1672
def __init__ (self , artist , ref_coord , unit = "points" ):
1672
- '''
1673
+ """
1673
1674
Parameters
1674
1675
----------
1675
1676
artist : `.Artist`, `.BboxBase`, or `.Transform`
@@ -1684,27 +1685,25 @@ def __init__(self, artist, ref_coord, unit="points"):
1684
1685
transform applied to this value.
1685
1686
1686
1687
unit : {'points, 'pixels'}
1687
- The screen units to use (pixels or points) for the offset
1688
- input.
1689
-
1690
- '''
1688
+ The screen units to use (pixels or points) for the offset input.
1689
+ """
1691
1690
self ._artist = artist
1692
1691
self ._ref_coord = ref_coord
1693
1692
self .set_unit (unit )
1694
1693
1695
1694
def set_unit (self , unit ):
1696
- '''
1695
+ """
1697
1696
The unit for input to the transform used by ``__call__``
1698
1697
1699
1698
Parameters
1700
1699
----------
1701
1700
unit : {'points', 'pixels'}
1702
- '''
1701
+ """
1703
1702
cbook ._check_in_list (["points" , "pixels" ], unit = unit )
1704
1703
self ._unit = unit
1705
1704
1706
1705
def get_unit (self ):
1707
- ' The unit for input to the transform used by ``__call__``'
1706
+ """ The unit for input to the transform used by ``__call__``."""
1708
1707
return self ._unit
1709
1708
1710
1709
def _get_scale (self , renderer ):
@@ -1715,7 +1714,7 @@ def _get_scale(self, renderer):
1715
1714
return renderer .points_to_pixels (1. )
1716
1715
1717
1716
def __call__ (self , renderer ):
1718
- '''
1717
+ """
1719
1718
Return the offset transform.
1720
1719
1721
1720
Parameters
@@ -1728,7 +1727,7 @@ def __call__(self, renderer):
1728
1727
transform : `Transform`
1729
1728
Maps (x, y) in pixel or point units to screen units
1730
1729
relative to the given artist.
1731
- '''
1730
+ """
1732
1731
if isinstance (self ._artist , Artist ):
1733
1732
bbox = self ._artist .get_window_extent (renderer )
1734
1733
l , b , w , h = bbox .bounds
@@ -1890,56 +1889,55 @@ def is_offset(s):
1890
1889
1891
1890
def set_annotation_clip (self , b ):
1892
1891
"""
1893
- set *annotation_clip* attribute .
1892
+ Set the annotation's clipping behavior .
1894
1893
1895
- * True: the annotation will only be drawn when self.xy is inside
1896
- the axes.
1897
- * False: the annotation will always be drawn regardless of its
1898
- position.
1899
- * None: the self.xy will be checked only if *xycoords* is "data"
1894
+ Parameters
1895
+ ----------
1896
+ b : bool or None
1897
+ - True: the annotation will only be drawn when self.xy is inside
1898
+ the axes.
1899
+ - False: the annotation will always be drawn regardless of its
1900
+ position.
1901
+ - None: the self.xy will be checked only if *xycoords* is "data".
1900
1902
"""
1901
1903
self ._annotation_clip = b
1902
1904
1903
1905
def get_annotation_clip (self ):
1904
1906
"""
1905
- Return *annotation_clip* attribute.
1906
- See :meth:`set_annotation_clip` for the meaning of return values.
1907
+ Return the annotation's clipping behavior.
1908
+
1909
+ See `set_annotation_clip` for the meaning of return values.
1907
1910
"""
1908
1911
return self ._annotation_clip
1909
1912
1910
1913
def _get_position_xy (self , renderer ):
1911
- "Return the pixel position of the annotated point."
1914
+ """ Return the pixel position of the annotated point."" "
1912
1915
x , y = self .xy
1913
1916
return self ._get_xy (renderer , x , y , self .xycoords )
1914
1917
1915
1918
def _check_xy (self , renderer , xy_pixel ):
1916
- """
1917
- given the xy pixel coordinate, check if the annotation need to
1918
- be drawn.
1919
- """
1920
-
1919
+ """Check whether the annotation at *xy_pixel* should be drawn."""
1921
1920
b = self .get_annotation_clip ()
1922
-
1923
1921
if b or (b is None and self .xycoords == "data" ):
1924
1922
# check if self.xy is inside the axes.
1925
- if not self .axes .contains_point (xy_pixel ):
1926
- return False
1927
-
1923
+ return self .axes .contains_point (xy_pixel )
1928
1924
return True
1929
1925
1930
1926
def draggable (self , state = None , use_blit = False ):
1931
1927
"""
1932
- Set the draggable state -- if state is
1933
-
1934
- * None : toggle the current state
1928
+ Set whether the annotation is draggable with the mouse.
1935
1929
1936
- * True : turn draggable on
1937
-
1938
- * False : turn draggable off
1930
+ Parameters
1931
+ ----------
1932
+ state : bool or None
1933
+ - True or False: set the draggability.
1934
+ - None: toggle the draggability.
1939
1935
1940
- If draggable is on, you can drag the annotation on the canvas with
1941
- the mouse. The DraggableAnnotation helper instance is returned if
1942
- draggable is on.
1936
+ Returns
1937
+ -------
1938
+ DraggableAnnotation or None
1939
+ If the annotation is draggable, the corresponding
1940
+ `.DraggableAnnotation` helper is returned.
1943
1941
"""
1944
1942
from matplotlib .offsetbox import DraggableAnnotation
1945
1943
is_draggable = self ._draggable is not None
0 commit comments