[Python] matplotlib latex text color

Discussão em 'Python' iniciado por Stack, Março 26, 2025.

  1. Stack

    Stack Membro Participativo

    I want to partially color some LaTeX text in my plot using the \textcolor{} command. I tried the following, but the text still appears black:

    import matplotlib
    matplotlib.use('TKAgg')

    from matplotlib import rc
    rc('text',usetex=True)
    rc('text.latex', preamble=r'\usepackage{color}')
    import matplotlib.pyplot as plt

    if __name__ == "__main__":
    fig = plt.figure()
    fig.text(0.5, 0.5, r'black \textcolor{red}{red}')
    plt.show()


    Changing the backend to pc as done here does not help. Any suggestions on how to do it?

    Continue reading...

Compartilhe esta Página