2016-07-03 2 views
1

라틴 문자를 파이썬으로 렌더링하려고합니다. 이것은 내가 어떻게 뭘하려 :파이썬으로 라텍스 텍스트를 렌더링

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

올바르게 렌더링 할 때, 정상적으로 출력 : 그러나 enter image description here

, 이것이 내가 무엇을 얻을 수 있습니다 : enter image description here

어떤 아이디어?

감사합니다.

답변

1

당신에 설치되어 있어야합니다 자신의 설치된 소프트웨어에 의해 라텍스 텍스트를 렌더링하는 코드에 다음 줄을 추가해야합니다 (기본적으로 MathText를 사용하기 matplotlib : http://matplotlib.org/api/mathtext_api.html를)

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

두 번째 문제는 (한 줄에 라텍스 문자열을 넣어야 할 것입니다 그리고 $ -brackets for를 잊어 버렸습니다. 행렬) :

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

관련 문제