我想有一个情节,其中字体是"计算机现代"(即latex 风格),但与x-ticks和y-ticks在粗体.
由于matplotlib最近的升级,我之前的过程不再有效.
这是我的老程序:
plt.rc('font', family='serif',size=24)
matplotlib.rc('text', usetex=True)
matplotlib.rc('legend', fontsize=24)
matplotlib.rcParams['text.latex.preamble'] = [r'\boldmath']
这是输出消息:
test_font.py:26: MatplotlibDeprecationWarning: Support for setting an rcParam that expects a str value to a non-str value is deprecated since 3.5 and support will be removed two minor releases later.
matplotlib.rcParams['text.latex.preamble'] = [r'\boldmath']
我已经决定一个可能的解决方案是使用"现代电脑"作为字体.这是我的例子:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
font = {'family' : 'serif',
'weight' : 'bold',
'size' : 12
}
matplotlib.rc('font', **font)
# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots(1,figsize=(9,6))
ax.plot(t, s)
ax.set(xlabel='time (s) $a_1$', ylabel='voltage (mV)',
title='About as simple as it gets, folks')
ax.grid()
fig.savefig("test.png")
plt.show()
结果是:
然而,我无法设置字体样式.
我try 将字体系列设置为"cmr10".这是代码:
font = {'family' : 'serif',
'weight' : 'bold',
'size' : 12,
'serif': 'cmr10'
}
matplotlib.rc('font', **font)
似乎"cmr10"让消失成为了一个大胆的 Select .
谢谢