(self, renderer, coords)
| 1699 | return self._get_xy_transform(renderer, coords).transform((x, y)) |
| 1700 | |
| 1701 | def _get_xy_transform(self, renderer, coords): |
| 1702 | |
| 1703 | if isinstance(coords, tuple): |
| 1704 | xcoord, ycoord = coords |
| 1705 | from matplotlib.transforms import blended_transform_factory |
| 1706 | tr1 = self._get_xy_transform(renderer, xcoord) |
| 1707 | tr2 = self._get_xy_transform(renderer, ycoord) |
| 1708 | return blended_transform_factory(tr1, tr2) |
| 1709 | elif callable(coords): |
| 1710 | tr = coords(renderer) |
| 1711 | if isinstance(tr, BboxBase): |
| 1712 | return BboxTransformTo(tr) |
| 1713 | elif isinstance(tr, Transform): |
| 1714 | return tr |
| 1715 | else: |
| 1716 | raise TypeError( |
| 1717 | f"xycoords callable must return a BboxBase or Transform, not a " |
| 1718 | f"{type(tr).__name__}") |
| 1719 | elif isinstance(coords, Artist): |
| 1720 | bbox = coords.get_window_extent(renderer) |
| 1721 | return BboxTransformTo(bbox) |
| 1722 | elif isinstance(coords, BboxBase): |
| 1723 | return BboxTransformTo(coords) |
| 1724 | elif isinstance(coords, Transform): |
| 1725 | return coords |
| 1726 | elif not isinstance(coords, str): |
| 1727 | raise TypeError( |
| 1728 | f"'xycoords' must be an instance of str, tuple[str, str], Artist, " |
| 1729 | f"Transform, or Callable, not a {type(coords).__name__}") |
| 1730 | |
| 1731 | if coords == 'data': |
| 1732 | return self.axes.transData |
| 1733 | elif coords == 'polar': |
| 1734 | from matplotlib.projections import PolarAxes |
| 1735 | return PolarAxes.PolarTransform() + self.axes.transData |
| 1736 | |
| 1737 | try: |
| 1738 | bbox_name, unit = coords.split() |
| 1739 | except ValueError: # i.e. len(coords.split()) != 2. |
| 1740 | raise ValueError(f"{coords!r} is not a valid coordinate") from None |
| 1741 | |
| 1742 | bbox0, xy0 = None, None |
| 1743 | |
| 1744 | # if unit is offset-like |
| 1745 | if bbox_name == "figure": |
| 1746 | bbox0 = self.get_figure(root=False).figbbox |
| 1747 | elif bbox_name == "subfigure": |
| 1748 | bbox0 = self.get_figure(root=False).bbox |
| 1749 | elif bbox_name == "axes": |
| 1750 | bbox0 = self.axes.bbox |
| 1751 | |
| 1752 | # reference x, y in display coordinate |
| 1753 | if bbox0 is not None: |
| 1754 | xy0 = bbox0.p0 |
| 1755 | elif bbox_name == "offset": |
| 1756 | xy0 = self._get_position_xy(renderer) |
| 1757 | else: |
| 1758 | raise ValueError(f"{coords!r} is not a valid coordinate") |
no test coverage detected