2016-07-03 15 views
1

Ich versuche, Latex-Text mit Python zu rendern. Das ist, was ich versucht zu tun: richtigRender Latex Text mit Python

import matplotlib.pyplot as plt 

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=10) 
fig = plt.gca() 
fig.axes.get_xaxis().set_visible(False) 
fig.axes.get_yaxis().set_visible(False) 
plt.draw() #or savefig 
plt.show() 

Wenn gemacht, es sollte Ausgabe: enter image description here

Dies ist jedoch, was ich bekommen: enter image description here

Irgendwelche Ideen?

Danke!

Antwort

1

Sie Latex Text durch Ihre eigene installierten Software zu machen (Standard matplotlib MathText verwenden: http://matplotlib.org/api/mathtext_api.html): muß dem Code diese Zeilen hinzufügen

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

Das zweite Problem ist, dass Sie Ihren Latex-String in eine Zeile setzen müssen (und du vergisst $ -Brackets dafür Matrizen):

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() 

enter image description here