matplotlab库默认的字体是不支持中文的,所以需要自定义。
import matplotlib.pyplot as plt
# 设置中文字体为SimSun
plt.rcParams['font.sans-serif'] = ['SimSun']
# 绘制图形
x = [1, 2, 3, 4, 5]
y = [10, 20, 30, 40, 50]
plt.plot(x, y, label='中文标签')
# 添加图例
plt.legend()
# 显示图形
plt.show()
matplotlab会自动去系统目录下寻找字体。