Render Latex text with python

后端 未结 2 545
闹比i
闹比i 2021-01-20 12:48

I\'m trying to render Latex text with python. This is what I tried to do:

import matplotlib.pyplot as plt

txte = r\"\"\"
The \\emph{characteristic polynomia         


        
2条回答
  •  礼貌的吻别
    2021-01-20 12:55

    You have to add to your code these lines to render latex text by your own installed software (by default matplotlib use MathText: http://matplotlib.org/api/mathtext_api.html):

    from matplotlib import rcParams
    rcParams['text.usetex'] = True
    

    The second problem is that you have to put your latex string to one line (and you forget $-brackets for matrices):

    import matplotlib.pyplot as plt
    from matplotlib import rcParams
    rcParams['text.usetex'] = True
    
    txte = r"The \emph{characteristic polynomial} $\chi(\lambda)$ of the $3 \times 3$~matrix \\ $\left( \begin{array}{ccc} a & b & c \\ d & e & f \\g & h & i \end{array} \right) $ \\is given by the formula\\ $ \chi(\lambda) = \left| \begin{array}{ccc} \lambda - a & -b & -c \\ -d & \lambda - e & -f \\ -g & -h & \lambda - i \end{array} \right|. $"
    
    
    plt.text(0.0, 0.0, txte, fontsize=14)
    ax = plt.gca()
    ax.axes.get_xaxis().set_visible(False)
    ax.axes.get_yaxis().set_visible(False)
    
    plt.show()
    

提交回复
热议问题