【发布时间】:2016-02-29 18:14:39
【问题描述】:
我正在拼命寻找“最简单的方法”来在我的 matplotlib 图形和我的 Latex 文档中获得外观相同的文本。
到目前为止,我的策略是:
为我的 Latex 图形设置明确的宽度,并使用 Matplotlib 设置相同的大小。这样,将 mpl 中的字体大小设置为等于 Latex 字体大小应该是第一步
在 mpl 中使用
usetex = True选项。我知道这应该使 mpl 使用 Latex 进行图中的所有文本处理(标题、标签、文本、注释等)。
我的问题是到最后我还是无法设置我想要的字体。
这是一个示例,其中水平轴标签字体与刻度标签明显不同,我确信这与我的乳胶文档的文本相同。
这是生成该图的代码:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
with plt.style.context('journal'):
fig_size = [3.4, 2.1]
fig = plt.figure(1, figsize=fig_size)
ax1 = plt.subplot(111)
ax1.plot([1,2,3,4,5], '+--')
ax1.set_xlabel(r'1 2 3 4.0 intensity [$10^{13}p$]')
plt.tight_layout()
fig.savefig('test.png') # I saved to png for SO but the goal is eps
我的journal mpl 样式表是
backend: PS
text.usetex: True
text.latex.unicode: True
font.family: lmodern # apparently no effect as usetex is true anyway
font.size: 10
axes.titlesize: 10
axes.labelsize: 10
axes.unicode_minus: True
axes.linewidth: 1
legend.fontsize: 10
xtick.labelsize: 10
xtick.major.size: 4
xtick.major.width: 0.5
ytick.labelsize: 10
lines.linewidth: 1.5
lines.markersize: 3
figure.titleweight: normal
savefig.dpi: 600
此外,我什至不确定我是否能够从计算机现代选择/切换到拉丁现代,部分原因是我的眼睛无法区分它们(这在某种程度上使这个问题无关紧要,但你知道。 .. 极客...)。
【问题讨论】:
-
我发布的答案似乎可以解决我的问题,但我仍然很想“一般”地对我的问题提供反馈。
标签: python matplotlib fonts