我拼命地試圖找到'最簡單的方法'來獲得我的matplotlib數字和我的latex文檔中看起來相同的文本。matplotlib和latex之間的一致字體
到目前爲止,我的策略是:
設置爲我的乳膠數字明確的寬度和設定Matplotlib大小相同。這樣設置mpl中的字體大小等於Latex字體大小應該是第一步
在mpl中使用
usetex = True
選項。我知道這應該使mpl在圖中使用Latex進行所有文本處理(標題,標籤,文本,註釋等)。
我的問題是,最後我仍然無法設置字體,因爲我想。
下面是一個橫軸標籤字體明顯不同於刻度標籤的示例,我相信它與我的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
此外,我甚至不相信我能夠選擇/從現代計算機切換到拉丁現代,部分是因爲我的眼睛無法區分它們(這在某種程度上使問題無關緊要,但您知道.. 。極客...)。
我張貼一個似乎解決了我的問題的答案,但是我仍然好奇地對我的問題「一般」有反饋意見。 –