MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / OffsetFrom

Class OffsetFrom

lib/matplotlib/text.py:1605–1676  ·  view source on GitHub ↗

Callable helper class for working with `Annotation`.

Source from the content-addressed store, hash-verified

1603
1604
1605class OffsetFrom:
1606 """Callable helper class for working with `Annotation`."""
1607
1608 def __init__(self, artist, ref_coord, unit="points"):
1609 """
1610 Parameters
1611 ----------
1612 artist : `~matplotlib.artist.Artist` or `.BboxBase` or `.Transform`
1613 The object to compute the offset from.
1614
1615 ref_coord : (float, float)
1616 If *artist* is an `.Artist` or `.BboxBase`, this values is
1617 the location to of the offset origin in fractions of the
1618 *artist* bounding box.
1619
1620 If *artist* is a transform, the offset origin is the
1621 transform applied to this value.
1622
1623 unit : {'points, 'pixels'}, default: 'points'
1624 The screen units to use (pixels or points) for the offset input.
1625 """
1626 self._artist = artist
1627 x, y = ref_coord # Make copy when ref_coord is an array (and check the shape).
1628 self._ref_coord = x, y
1629 self.set_unit(unit)
1630
1631 def set_unit(self, unit):
1632 """
1633 Set the unit for input to the transform used by ``__call__``.
1634
1635 Parameters
1636 ----------
1637 unit : {'points', 'pixels'}
1638 """
1639 _api.check_in_list(["points", "pixels"], unit=unit)
1640 self._unit = unit
1641
1642 def get_unit(self):
1643 """Return the unit for input to the transform used by ``__call__``."""
1644 return self._unit
1645
1646 def __call__(self, renderer):
1647 """
1648 Return the offset transform.
1649
1650 Parameters
1651 ----------
1652 renderer : `RendererBase`
1653 The renderer to use to compute the offset
1654
1655 Returns
1656 -------
1657 `Transform`
1658 Maps (x, y) in pixel or point units to screen units
1659 relative to the given artist.
1660 """
1661 if isinstance(self._artist, Artist):
1662 bbox = self._artist.get_window_extent(renderer)

Callers 3

annotations.pyFile · 0.90
annotation_demo.pyFile · 0.90

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…