Skip to content

Commit

Permalink
Merge pull request #11568 from fredrik-1/figure.text
Browse files Browse the repository at this point in the history
Figure.text changes
  • Loading branch information
jklymak committed Jul 4, 2018
2 parents 2afeec7 + ed56906 commit 3bf263b
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions lib/matplotlib/figure.py
Expand Up @@ -41,7 +41,7 @@
from matplotlib.patches import Rectangle
from matplotlib.projections import (get_projection_names,
process_projection_requirements)
from matplotlib.text import Text, _process_text_args
from matplotlib.text import Text, TextWithDash
from matplotlib.transforms import (Affine2D, Bbox, BboxTransformTo,
TransformedBbox)
import matplotlib._layoutbox as layoutbox
Expand Down Expand Up @@ -1716,32 +1716,63 @@ def legend(self, *args, **kwargs):
return l

@docstring.dedent_interpd
def text(self, x, y, s, *args, **kwargs):
def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):
"""
Add text to figure.
Call signature::
Parameters
----------
x, y : float
The position to place the text. By default, this is in figure
coordinates, floats in [0, 1]. The coordinate system can be changed
using the *transform* keyword.
s : str
The text string.
text(x, y, s, fontdict=None, **kwargs)
fontdict : dictionary, optional, default: None
A dictionary to override the default text properties. If fontdict
is None, the defaults are determined by your rc parameters. A
property in *kwargs* override the same property in fontdict.
Add text to figure at location *x*, *y* (relative 0-1
coords). See :func:`~matplotlib.pyplot.text` for the meaning
of the other arguments.
withdash : boolean, optional, default: False
Creates a `~matplotlib.text.TextWithDash` instance instead of a
`~matplotlib.text.Text` instance.
Other Parameters
----------------
**kwargs : `~matplotlib.text.Text` properties
Other miscellaneous text parameters.
%(Text)s
kwargs control the :class:`~matplotlib.text.Text` properties:
Returns
-------
text : `~.text.Text`
%(Text)s
See Also
--------
.Axes.text
.pyplot.text
"""
default = dict(transform=self.transFigure)

if withdash:
text = TextWithDash(x=x, y=y, text=s)
else:
text = Text(x=x, y=y, text=s)

text.update(default)
if fontdict is not None:
text.update(fontdict)
text.update(kwargs)

override = _process_text_args({}, *args, **kwargs)
t = Text(x=x, y=y, text=s)
text.set_figure(self)
text.stale_callback = _stale_figure_callback

t.update(override)
self._set_artist_props(t)
self.texts.append(t)
t._remove_method = self.texts.remove
self.texts.append(text)
text._remove_method = self.texts.remove
self.stale = True
return t
return text

def _set_artist_props(self, a):
if a != self:
Expand Down

0 comments on commit 3bf263b

Please sign in to comment.