我正在将matplotlib.pyplot绘图导出到.pgf文件,以便在Latex中使用它们,因此,在python中,我要先指定正确的字体系列和字体大小。当图例的格式正确时,轴标签显示为字体大小的2pt左右偏移量,即使已指定,它们也不以粗体显示。不能将RC参数与样式表一起使用吗?这是我的代码:
import matplotlib.pyplot as plt
import matplotlib.style as pltstyle
pltstyle.use('ggplot')
from matplotlib import rc
from matplotlib import rcParams
rc('font', **{'family': 'serif', 'serif': ['Latin Modern Roman']})
rc('text', usetex=True)
rc('font', size=8)
rc('font', weight='bold')
rc('text.latex', preamble=r'\usepackage{amsmath}')
testx = [1,2]
testy = [1,2]
fig, ax1 = plt.subplots()
ax1.set_xlabel('This Font is too large')
ax1.set_ylabel('And not bold')
ax1.plot(testx, testy, color='tab:red', marker='o', label='Right Font Style')
plt.legend()
plt.savefig('test.png', bbox_inches='tight')
我可以强制绘图使用RC参数吗?
当您使用乳胶模式(usetex = True)时,并且如果您想以粗体显示轴,则应编写:
ax1.set_xlabel(r'\textbf{This Font is too large}')
代替
ax1.set_xlabel('This Font is too large')