[Python] How to convert annotation in bold text?

Discussão em 'Python' iniciado por Stack, Junho 28, 2025.

  1. Stack

    Stack Membro Participativo

    This is a reproducible program displaying an annotated line:

    import numpy as np
    import matplotlib.pyplot as plt
    plt.rcParams['text.usetex'] = True

    fig, ax = plt.subplots(figsize=(6, 4))

    point1 = [0, 1]
    point2 = [np.sqrt(2), 0]
    x_values = [point1[0], point2[0]]
    y_values = [point1[1], point2[1]]

    ax.plot(x_values, y_values, 'bo', linestyle="-")
    ax.annotate( r"$y = -\,\frac{1}{\sqrt(2)}x + 1$", xy = (0.2, 0.7), rotation = -35, fontsize = 12)

    plt.show()


    Now looking for the best way to display the annotation in bold .

    I tried to use \textbf:

    ax.annotate( r"\textbf{$y = -\,\frac{1}{\sqrt(2)}x + 1$}", xy = (0.2, 0.7), rotation = -35, fontsize = 12)


    but nothing changed. I guess a misuse of \textbf... What would be the proper use?

    Continue reading...

Compartilhe esta Página