2016-07-03 75 views
1

我想用python呈現乳膠文本。這就是我試圖做的:用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() 

當正確地呈現,它應該輸出: enter image description here

然而,這是我所得到的: enter image description here

任何想法?

謝謝!

回答

1

你有你自己安裝的軟件添加到您的這幾行代碼,以使乳膠文本(默認情況下matplotlib使用MathText:http://matplotlib.org/api/mathtext_api.html):

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

的第二個問題是,你必須把你的乳膠串到一條線(而你忘記了$ -brackets矩陣):

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