繁体   English   中英

Python:在情节中使用乳胶时,图例消失

[英]Python: Legend disappears when using latex in plot

我在Python中有一个可以正常使用python文本的绘图,但是当我尝试在绘图中使用乳胶时,图例消失了,我根本无法保存该绘图。 我不确定这是否重要,但是我正在使用2011年的Macbook Pro和OS 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()

删除情节标题中的换行符应该可以完成这项工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM