1 python latex matplotlib ipython ipython-notebook
之前已经回答过在IPython Notebook中显示LaTeX的行,但是在IPython Notebook中绘图时,你如何用LaTeX字符串标记绘图的轴?
它在IPython中的工作方式与在独立脚本中的工作方式相同.这个例子来自文档:
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rc('text', usetex = True)
mpl.rc('font', family = 'serif')
plt.figure(1, figsize = (6, 4))
ax = plt.axes([0.1, 0.1, 0.8, 0.7])
t = np.arange(0.0, 1.0+0.01, 0.01)
s = cos(2*2*pi*t)+2
plt.plot(t, s)
plt.xlabel(r'\textbf{time (s)}')
plt.ylabel(r'\textit{voltage (mV)}', fontsize = 16)
plt.title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
fontsize = 16, color = 'r')
plt.grid(True)
plt.savefig('tex_demo')
plt.show()
Run Code Online (Sandbox Code Playgroud)