def maybe_center_plot(result):
    """Embeds a possible tikz image inside a center environment.

    Searches for matplotlib2tikz last commend line to detect tikz images.

    Args:
        result: The code execution result

    Returns:
        The input result if no tikzpicture was found, otherwise a centered
        version.
    """
    begin = re.search('(% .* matplotlib2tikz v.*)', result)
    if begin:
        result = ('\\begin{center}\n' + result[begin.end():] +
                  '\n\\end{center}')
    return result
Embeds a possible tikz image inside a center environment.

    Searches for matplotlib2tikz last commend line to detect tikz images.

    Args:
        result: The code execution result

    Returns:
        The input result if no tikzpicture was found, otherwise a centered
        version.