使用jupyter / ipython在python中执行以下代码时,Latex符号无法正确显示。任何想法为什么会这样?
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
x = np.linspace(0,3)
y = np.sin(x)
plt.plot(x,y)
plt.title(r'$\beta \rho \lambda \xi$',fontsize=30)
输出:
答案 0 :(得分:2)
IPython笔记本使用MathJax在html / markdown中呈现LaTeX。把你的LaTeX数学放在$$。
$$c = \sqrt{a^2 + b^2}$$
你必须写:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,3)
y = np.sin(x)
plt.plot(x,y)
plt.title(r'$$\beta \rho \lambda \xi$$',fontsize=30)
plt.show()
或者您可以显示Python的LaTeX / Math输出,如notebook tour末尾所示:
from IPython.display import display, Math, Latex
display(Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'))
其他解决方案:
import numpy as np
from matplotlib import pyplot as plt
import matplotlib as mpl
mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}'] #for \text command
x = np.linspace(0,3)
y = np.sin(x)
plt.plot(x,y)
plt.title(r'$text{\beta \rho \lambda \xi}$',fontsize=30)
plt.show()