配置字体系列

你可以明确地设置为给定字体样式拾取的字体系列(例如,‘serif’、‘sans-serif’或‘monSpace’)。

在下面的示例中,我们只允许一个字体系列(Tahoma)用于sans-serif字体样式。你是font.family rc param的默认系列,例如:

  1. rcParams['font.family'] = 'sans-serif'

并为font.family设置一个字体样式列表,以尝试按顺序查找:

  1. rcParams['font.sans-serif'] = ['Tahoma', 'DejaVu Sans',
  2. 'Lucida Grande', 'Verdana']
  1. from matplotlib import rcParams
  2. rcParams['font.family'] = 'sans-serif'
  3. rcParams['font.sans-serif'] = ['Tahoma']
  4. import matplotlib.pyplot as plt
  5. fig, ax = plt.subplots()
  6. ax.plot([1, 2, 3], label='test')
  7. ax.legend()
  8. plt.show()

下载这个示例