Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bf263b

Browse files
authored
Merge pull request #11568 from fredrik-1/figure.text
Figure.text changes
2 parents 2afeec7 + ed56906 commit 3bf263b

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

lib/matplotlib/figure.py

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from matplotlib.patches import Rectangle
4242
from matplotlib.projections import (get_projection_names,
4343
process_projection_requirements)
44-
from matplotlib.text import Text, _process_text_args
44+
from matplotlib.text import Text, TextWithDash
4545
from matplotlib.transforms import (Affine2D, Bbox, BboxTransformTo,
4646
TransformedBbox)
4747
import matplotlib._layoutbox as layoutbox
@@ -1716,32 +1716,63 @@ def legend(self, *args, **kwargs):
17161716
return l
17171717

17181718
@docstring.dedent_interpd
1719-
def text(self, x, y, s, *args, **kwargs):
1719+
def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):
17201720
"""
17211721
Add text to figure.
17221722
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.
17241732
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.
17261737
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
17301747
1731-
kwargs control the :class:`~matplotlib.text.Text` properties:
1748+
Returns
1749+
-------
1750+
text : `~.text.Text`
17321751
1733-
%(Text)s
1752+
See Also
1753+
--------
1754+
.Axes.text
1755+
.pyplot.text
17341756
"""
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)
17351768

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
17381771

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
17431774
self.stale = True
1744-
return t
1775+
return text
17451776

17461777
def _set_artist_props(self, a):
17471778
if a != self:

0 commit comments

Comments
 (0)