Python:在绘图中使用latex时,图例消失

Python:在绘图中使用latex时,图例消失,python,plot,latex,Python,Plot,Latex,我在Python中有一个使用普通Python文本可以正常工作的绘图,但是当我尝试在绘图中使用latex时,图例消失了,我根本无法保存绘图。我不确定这是否重要,但我使用的是2011年的Macbook Pro操作系统Sierra 10.12.4 下面是我添加latex之前的代码: import matplotlib.pyplot as pl import pylab x = [0., 20., 40.] y = [1.07e-4, 1.0e-4, 8.94e-5] y_error = [5.74e

我在Python中有一个使用普通Python文本可以正常工作的绘图,但是当我尝试在绘图中使用latex时,图例消失了,我根本无法保存绘图。我不确定这是否重要,但我使用的是2011年的Macbook Pro操作系统Sierra 10.12.4

下面是我添加latex之前的代码:

import matplotlib.pyplot as pl
import pylab

x = [0., 20., 40.]
y = [1.07e-4, 1.0e-4, 8.94e-5]
y_error = [5.74e-6, 2.46e-6, 3.11e-6]

pl.plot(x, y, "ro", label = "FZ200N")
pl.errorbar(x, y, yerr = y_error, linestyle = "None")

pl.title("Change in the Leakage Current with Annealing Time at 0C" + "\n")
pl.xlabel("Annealing Time (min)")#x label
pl.ylabel("Leakage Current (A)")#y label
pl.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
pylab.xlim([-1,42])
pylab.legend(bbox_to_anchor=(1.0, 1), loc=2, borderaxespad=0.)
pl.show()
import matplotlib.pyplot as pl
import pylab

x = [0., 20., 40.]
y = [1.07e-4, 1.0e-4, 8.94e-5]
y_error = [5.74e-6, 2.46e-6, 3.11e-6]

pl.rc('text', usetex=True)
pl.rc('font', family='serif')
pylab.plot(x, y, "ro", label = r"FZ200N")
pl.errorbar(x, y, yerr = y_error, linestyle = "None")
pl.title(r"Change in the Depletion Voltage with Annealing Time at 0$^\circ$C" + "\n", fontsize = 14)
pl.xlabel(r"Annealing Time (min)", fontsize = 14)#x label
pl.ylabel(r"Depletion Voltage (V)", fontsize = 14)#y label
pl.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
pylab.xlim([-1,42])
pylab.legend(bbox_to_anchor=(1.0, 1), loc=2, borderaxespad=0.)
pl.show()
现在在我加入乳胶后:

import matplotlib.pyplot as pl
import pylab

x = [0., 20., 40.]
y = [1.07e-4, 1.0e-4, 8.94e-5]
y_error = [5.74e-6, 2.46e-6, 3.11e-6]

pl.plot(x, y, "ro", label = "FZ200N")
pl.errorbar(x, y, yerr = y_error, linestyle = "None")

pl.title("Change in the Leakage Current with Annealing Time at 0C" + "\n")
pl.xlabel("Annealing Time (min)")#x label
pl.ylabel("Leakage Current (A)")#y label
pl.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
pylab.xlim([-1,42])
pylab.legend(bbox_to_anchor=(1.0, 1), loc=2, borderaxespad=0.)
pl.show()
import matplotlib.pyplot as pl
import pylab

x = [0., 20., 40.]
y = [1.07e-4, 1.0e-4, 8.94e-5]
y_error = [5.74e-6, 2.46e-6, 3.11e-6]

pl.rc('text', usetex=True)
pl.rc('font', family='serif')
pylab.plot(x, y, "ro", label = r"FZ200N")
pl.errorbar(x, y, yerr = y_error, linestyle = "None")
pl.title(r"Change in the Depletion Voltage with Annealing Time at 0$^\circ$C" + "\n", fontsize = 14)
pl.xlabel(r"Annealing Time (min)", fontsize = 14)#x label
pl.ylabel(r"Depletion Voltage (V)", fontsize = 14)#y label
pl.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
pylab.xlim([-1,42])
pylab.legend(bbox_to_anchor=(1.0, 1), loc=2, borderaxespad=0.)
pl.show()

删除绘图标题中的换行符应该可以实现这一点