需要首先下载所需字体
黑体:simhei.ttf
宋体:SimSun.ttf
# 黑体 from matplotlib import pyplot as plt from matplotlib.font_manager import FontProperties # 在此设置字体及大小 font = FontProperties(fname=r"./simhei.ttf", size=14) plt.figure() plt.xlabel(u'x轴', FontProperties=font) plt.ylabel(u'y轴', FontProperties=font) plt.title(u'test——绘图', FontProperties=font) import numpy as np plt.plot(np.arange(1, 10), np.arange(1, 10))
宋体:
# 宋体 from matplotlib import pyplot as plt from matplotlib.font_manager import FontProperties # 在此设置字体及大小 font = FontProperties(fname=r"./SimSun.ttf", size=14) plt.figure() plt.xlabel(u'x轴', FontProperties=font) plt.ylabel(u'y轴', FontProperties=font) plt.title(u'test——绘图', FontProperties=font) import numpy as np plt.plot(np.arange(1, 10), np.arange(1, 10))



