将 matplotlib 字体设成 Times New Roman,见 [1,2],但默认是加粗的,想改成不加粗,见 [3,4]。例程:
import matplotlib as mpl
mpl.rcParams['text.usetex'] = True
# 换成**不**加粗
import matplotlib.font_manager
del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()
# 用 Times New Roman 字体
mpl.rcParams['font.family'] = 'Times New Roman'
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], label='test')
ax.legend()
plt.show()
- 但是,执行一次之后,就回不去原本加粗的了,注释掉也没用…目前还不知道怎么重置。
- 看
_rebuild()
的代码,影响的配置文件似乎是C:\Users\iTom\.matplotlib\
下的几个 .json 文件。
Rendering
References
- How to set the label Fonts as “Time New Roman” by drawparallels in python
- Configuring the font family
- Matplotlib: Times New Roman appears bold
- Incorrect selection of Times New Roman Bold
- matplotlib.font_manager
- matplotlib设置宋体和Times New Roman体
- Matplotlib中文乱码解决方案(两种方式)
- PYTHON MATPLOTLIB 画黑白的柱状图(论文专用)
- matplotlib设置中英文多种字体混合坐标轴名称