Skip to content

flexitext

Draw text with multiple formats.

Parameters:

Name Type Description Default
x float

The horizontal position to place the text. By default, this is in axes fraction coordinates.

required
y float

The vertical position to place the text. By default, this is in axes fraction coordinates.

required
ha str

Horizontal alignment. Must be one of 'center', 'right', or 'left'.

'left'
va str

Horizontal alignment. Must be one of 'center', 'top', or 'bottom'.

'center'
ma str

Alignment for multiline texts. The layout of the bounding box of all the lines is determined by the ha and va properties. This property controls the alignment of the text lines within that box.

'left'
mva str

Vertical alignment for text within multiline texts. Can be one of "top", "bottom", "left", "right", "center", or "baseline". Defaults to "baseline".

'baseline'
xycoords str

The coordinate system for x and y. Must be one of 'axes fraction' or 'figure fraction'.

'axes fraction'
ax Axes

Matplotlib Axes. The default value means the Axes is obtained with plt.gca().

None

Returns:

Name Type Description
annotation_box AnnotationBbox
Source code in flexitext/flexitext.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def flexitext(
    x,
    y,
    s,
    ha="left",
    va="center",
    ma="left",
    mva="baseline",
    xycoords="axes fraction",
    ax=None,
):
    """Draw text with multiple formats.

    Parameters
    ----------
    x : float
        The horizontal position to place the text. By default, this is in axes fraction
        coordinates.
    y : float
        The vertical position to place the text. By default, this is in axes fraction
        coordinates.
    ha : str
        Horizontal alignment. Must be one of `'center'`, `'right'`, or `'left'`.
    va : str
        Horizontal alignment. Must be one of `'center'`, `'top'`, or `'bottom'`.
    ma : str
        Alignment for multiline texts. The layout of the bounding box of all the lines is
        determined by the `ha` and `va` properties. This property controls the alignment of the
        text lines within that box.
    mva : str
        Vertical alignment for text within multiline texts. Can be one of `"top"`, `"bottom"`,
        `"left"`, `"right"`, `"center"`, or `"baseline"`. Defaults to `"baseline"`.
    xycoords : str
        The coordinate system for `x` and `y`. Must be one of `'axes fraction'` or
        `'figure fraction'`.
    ax : matplotlib.axes.Axes
        Matplotlib `Axes`. The default value means the `Axes` is obtained with `plt.gca()`.

    Returns
    -------
    annotation_box : matplotlib.offsetbox.AnnotationBbox
    """
    return FlexiText(*make_texts(s)).plot(x, y, ha, va, ma, mva, xycoords, ax)