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

2024-05-15 03:03:59 发布

您现在位置:Python中文网/ 问答频道 /正文

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

以下是添加乳胶前的代码:

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

Tags: import绘图rotimeplotmatplotlibaserror

热门问题