from matplotlib\text.py
@cbook._define_aliases({
"color": ["c"],
"fontfamily": ["family"],
"fontproperties": ["font_properties"],
"horizontalalignment": ["ha"],
"multialignment": ["ma"],
"fontname": ["name"],
"fontsize": ["size"],
"fontstretch": ["stretch"],
"fontstyle": ["style"],
"fontvariant": ["variant"],
"verticalalignment": ["va"],
"fontweight": ["weight"],
})
class Text(Artist):
"""Handle storing and drawing of text in window or data coordinates."""
zorder = 3
_cached = cbook.maxdict(50)
def __repr__(self):
return "Text(%s, %s, %s)" % (self._x, self._y, repr(self._text))
def __init__(self,
x=0, y=0, text='',
color=None,
verticalalignment='baseline',
horizontalalignment='left',
multialignment=None,
fontproperties=None,
rotation=None,
linespacing=None,
rotation_mode=None,
usetex=None,
wrap=False,
**kwargs
):
"""
Create a `.Text` instance at *x*, *y* with string *text*.
Valid kwargs are
%(Text)s
"""
Artist.__init__(self)
self._x, self._y = x, y
if color is None:
color = rcParams['text.color']
if fontproperties is None:
fontproperties = FontProperties()
elif isinstance(fontproperties, str):
fontproperties = FontProperties(fontproperties)
self._text = ''
self.set_text(text)
self.set_color(color)
self.set_usetex(usetex)
self.set_wrap(wrap)
self.set_verticalalignment(verticalalignment)
self.set_horizontalalignment(horizontalalignment)
self._multialignment = multialignment
self._rotation = rotation
self._fontproperties = fontproperties
self._bbox_patch = None
self._renderer = None
if linespacing is None:
linespacing = 1.2
self._linespacing = linespacing
self.set_rotation_mode(rotation_mode)
self.update(kwargs)