Matplotlib:Times New Roman不显示粗体。为什么?

2024-04-25 07:32:36 发布

您现在位置:Python中文网/ 问答频道 /正文

当字体为Times New Roman时,我无法获得粗体轴标签和记号标签。但是,粗体选项适用于其他字体。我正在起诉python 3.7和matplotlib 3.1.3。请帮忙

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt


mpl.rcParams['font.size'] = 15
mpl.rcParams['font.weight'] = 'bold'
mpl.rcParams['axes.labelweight'] = 'bold'


print(f'Matplotlib Version: {mpl.__version__}')
# Matplotlib Version: 3.1.3


# FIGURE 1 (TIMES NEW ROMAN)
mpl.rcParams['font.family'] = 'Times'

fig, ax = plt.subplots()
ax.plot(np.random.randn(100), '-k')
ax.set_xlabel('Test 1')
ax.set_ylabel('Test 2')
ax.set_title('TIMES NEW ROMAN')
plt.show()
plt.close()


# FIGURE 2 (ARIAL)
mpl.rcParams['font.family'] = 'Arial'

fig, ax = plt.subplots()
ax.plot(np.random.randn(100), '-k')
ax.set_xlabel('Test 1')
ax.set_ylabel('Test 2')
ax.set_title('ARIAL')
plt.show()
plt.close()


[Times New Roman][1]
[Arial][2]

  [1]: https://i.stack.imgur.com/kyn8C.png
  [2]: https://i.stack.imgur.com/mVZlU.png

Tags: testimportnewmatplotlibasnp字体plt