import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
指定字体文件路径
font_path = ‘/usr/share/fonts/SIMHEI.TTF’
font_prop = FontProperties(fname=font_path)
示例代码
plt.plot([1, 2, 3], [4, 5, 6])
plt.title(‘示例图表’, fontproperties=font_prop)
plt.xlabel(‘X轴’, fontproperties=font_prop)
plt.ylabel(‘Y轴’, fontproperties=font_prop)
plt.savefig(‘test.png’)