如果我在启用 LaTeX 的情况下运行以下代码 (
usetex=True
),那么我会在小数点逗号和后面的第一个数字之间出现奇怪的间距。有谁知道如何解决这个问题吗?
import matplotlib.pyplot as plt
import locale
plt.style.use('classic')
locale.setlocale(locale.LC_NUMERIC, 'de_DE')
plt.rc('text', usetex=False)
font = {'family':'serif','size':14}
plt.rc('font',**font)
plt.rcParams['axes.formatter.use_locale'] = True
a=[.1,.2,.3,.4,.5]
b=[.1,.2,.3,.4,.5]
plt.plot(a,b)
plt.show()
另请参阅附图以进行澄清:
谢谢!
使用 LaTeX-Package
icomma
解决了问题!
import matplotlib.pyplot as plt
import locale
plt.style.use('classic')
locale.setlocale(locale.LC_NUMERIC, 'de_DE')
plt.rc('text', usetex=True)
font = {'family':'serif','size':14}
plt.rc('font',**font)
# Add the following two lines to the initial code:
params= {'text.latex.preamble' : [r'\usepackage{icomma}']}
plt.rcParams.update(params)
plt.rcParams['axes.formatter.use_locale'] = True
a=[.1,.2,.3,.4,.5]
b=[.1,.2,.3,.4,.5]
plt.plot(a,b)
plt.show()
对 wohoo 答案的补充,因为这对我不起作用。
而不是建议的
params = {'text.latex.preamble' : [r'\usepackage{icomma}']}
我删除了方括号并输入了
params= {'text.latex.preamble' : r'\usepackage{icomma}'}
这为我解决了问题并删除了逗号后面的空格。