【发布时间】:2018-07-18 15:19:50
【问题描述】:
我正在尝试使用 pgf 在 matplotlib 中实现无衬线轴标签和刻度。我想通过 rcParams 来控制它,所以我让它适用于所有后续的情节。目前,我正在使用
"pgf.rcfonts":False,
"pgf.texsystem": "pdflatex",
"text.usetex": True,
"font.family": "sans-serif",
我改编自 mpl 文档。它确实将我在图中的所有文本设置为无衬线字体。但是,数字以衬线字体保存。我希望它们是无衬线的。一旦我强制格式化,它的无衬线字体。有什么办法让它自动做到这一点? MinEx 紧随其后...
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import FormatStrFormatter
#define style
style = {
"pgf.rcfonts":False,
"pgf.texsystem": "pdflatex",
"text.usetex": True,
"font.family": "sans-serif"
}
#set
mpl.rcParams.update(style)
#get data
data = np.random.random(100)
#set up plot
f,ax = plt.subplots()
ax.plot(data)
#label something
ax.set_xlabel('Runner')
标签现在没有了。蜱虫不是!但是打电话的时候
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
他们是。
【问题讨论】:
-
这也是传说中的问题。我将其追溯到 pgf。如果我在 mpl.rc 中添加 sansmath 包,它确实可以在 mpl 中工作。但是,查看 pgf,它并没有强制数字。标签在前面得到 \sffamily,数字被直接解析,因此不明白。
-
好的,如果我使用手动方式,就会出现另一个问题。它确实将 sans-serif 中的数字解析为我的 tex 文档,但 FormatStrFormatter 在我需要德语时将语言环境重置为美国
标签: python matplotlib formatting