#查询可用字体
from matplotlib import pyplot as plt
import matplotlib
a=sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])
for i in a:
print(i)
#查询字体缓存目录,清空目录。
import matplotlib
print(matplotlib.get_cachedir())
#根据输出的文件目录,进入上一级目录下tts目录,下载SimHei.ttf,存入这个目录。
import matplotlib
matplotlib.matplotlib_fname()
wget SimHei字体
https://github.com/StellarCN/scp_zh/blob/master/fonts/SimHei.ttf
https://github.com/YuchenS1/Matplotlib-Chinese-Fonts/blob/master/SimHei.ttf
设置字体
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.size'] = '20'
plt.rcParams['font.sans-serif'] = ['SimHei']