def text_alignment ( x , y ) : if x == 0 : ha = "center" elif x > 0 : ha = "left" else : ha = "right" if y == 0 : va = "center" elif y > 0 : va = "bottom" else : va = "top" return ha , va
how to get horizontal alignment on python
Align text labels based on the x - and y - axis coordinate values .
def text_alignment(x, y):
    """
    Align text labels based on the x- and y-axis coordinate values.

    This function is used for computing the appropriate alignment of the text
    label.

    For example, if the text is on the "right" side of the plot, we want it to
    be left-aligned. If the text is on the "top" side of the plot, we want it
    to be bottom-aligned.

    :param x, y: (`int` or `float`) x- and y-axis coordinate respectively.
    :returns: A 2-tuple of strings, the horizontal and vertical alignments
        respectively.
    """
    if x == 0:
        ha = "center"
    elif x > 0:
        ha = "left"
    else:
        ha = "right"
    if y == 0:
        va = "center"
    elif y > 0:
        va = "bottom"
    else:
        va = "top"

    return ha, va