环境
Python 3.6, matplotlib 3, Linux
方法1:
- 查找或拷贝字体文件到 matplotlib 库的 fonts 目录.
例如微软雅黑字体
: /.../python3.6/site-packages/matplotlib/mpl-data/fonts/ttf/msyh.ttf - 删除 ~/.cache/matplotlib 的 cache 目录.
- 设置字体
import matplotlib.pyplot as pyplot |
方法2: FontProperties
from matplotlib import font_manager |
这种方法比较不优雅, 临时或测试可以用用.
其他
查询 matplotlibrc 配置文件的位置:
import matplotlib |
查询使用字体的位置和信息:
from matplotlib.font_manager import findfont, FontProperties |
doc
Configuring the font family
Customizing Matplotlib with style sheets and rcParams