|
41 | 41 | from matplotlib.patches import Rectangle
|
42 | 42 | from matplotlib.projections import (get_projection_names,
|
43 | 43 | process_projection_requirements)
|
44 |
| -from matplotlib.text import Text, _process_text_args |
| 44 | +from matplotlib.text import Text, TextWithDash |
45 | 45 | from matplotlib.transforms import (Affine2D, Bbox, BboxTransformTo,
|
46 | 46 | TransformedBbox)
|
47 | 47 | import matplotlib._layoutbox as layoutbox
|
@@ -1716,32 +1716,63 @@ def legend(self, *args, **kwargs):
|
1716 | 1716 | return l
|
1717 | 1717 |
|
1718 | 1718 | @docstring.dedent_interpd
|
1719 |
| - def text(self, x, y, s, *args, **kwargs): |
| 1719 | + def text(self, x, y, s, fontdict=None, withdash=False, **kwargs): |
1720 | 1720 | """
|
1721 | 1721 | Add text to figure.
|
1722 | 1722 |
|
1723 |
| - Call signature:: |
| 1723 | + Parameters |
| 1724 | + ---------- |
| 1725 | + x, y : float |
| 1726 | + The position to place the text. By default, this is in figure |
| 1727 | + coordinates, floats in [0, 1]. The coordinate system can be changed |
| 1728 | + using the *transform* keyword. |
| 1729 | +
|
| 1730 | + s : str |
| 1731 | + The text string. |
1724 | 1732 |
|
1725 |
| - text(x, y, s, fontdict=None, **kwargs) |
| 1733 | + fontdict : dictionary, optional, default: None |
| 1734 | + A dictionary to override the default text properties. If fontdict |
| 1735 | + is None, the defaults are determined by your rc parameters. A |
| 1736 | + property in *kwargs* override the same property in fontdict. |
1726 | 1737 |
|
1727 |
| - Add text to figure at location *x*, *y* (relative 0-1 |
1728 |
| - coords). See :func:`~matplotlib.pyplot.text` for the meaning |
1729 |
| - of the other arguments. |
| 1738 | + withdash : boolean, optional, default: False |
| 1739 | + Creates a `~matplotlib.text.TextWithDash` instance instead of a |
| 1740 | + `~matplotlib.text.Text` instance. |
| 1741 | +
|
| 1742 | + Other Parameters |
| 1743 | + ---------------- |
| 1744 | + **kwargs : `~matplotlib.text.Text` properties |
| 1745 | + Other miscellaneous text parameters. |
| 1746 | + %(Text)s |
1730 | 1747 |
|
1731 |
| - kwargs control the :class:`~matplotlib.text.Text` properties: |
| 1748 | + Returns |
| 1749 | + ------- |
| 1750 | + text : `~.text.Text` |
1732 | 1751 |
|
1733 |
| - %(Text)s |
| 1752 | + See Also |
| 1753 | + -------- |
| 1754 | + .Axes.text |
| 1755 | + .pyplot.text |
1734 | 1756 | """
|
| 1757 | + default = dict(transform=self.transFigure) |
| 1758 | + |
| 1759 | + if withdash: |
| 1760 | + text = TextWithDash(x=x, y=y, text=s) |
| 1761 | + else: |
| 1762 | + text = Text(x=x, y=y, text=s) |
| 1763 | + |
| 1764 | + text.update(default) |
| 1765 | + if fontdict is not None: |
| 1766 | + text.update(fontdict) |
| 1767 | + text.update(kwargs) |
1735 | 1768 |
|
1736 |
| - override = _process_text_args({}, *args, **kwargs) |
1737 |
| - t = Text(x=x, y=y, text=s) |
| 1769 | + text.set_figure(self) |
| 1770 | + text.stale_callback = _stale_figure_callback |
1738 | 1771 |
|
1739 |
| - t.update(override) |
1740 |
| - self._set_artist_props(t) |
1741 |
| - self.texts.append(t) |
1742 |
| - t._remove_method = self.texts.remove |
| 1772 | + self.texts.append(text) |
| 1773 | + text._remove_method = self.texts.remove |
1743 | 1774 | self.stale = True
|
1744 |
| - return t |
| 1775 | + return text |
1745 | 1776 |
|
1746 | 1777 | def _set_artist_props(self, a):
|
1747 | 1778 | if a != self:
|
|
0 commit comments