解决matplotlib中文乱码问题方案众多,我认为如下方案是最简单的一个。

1、从电脑中搜索simhei字体,如下示意图是mac检索结果,或者直接搜索simhei.ttf下载字体

拷贝到指定路径:/path/to/mex/simhei.ttf 

解决matplotlib中文乱码最简单方案_搜索

2、matplotlib 加载字体

def plot_with_chinese():
     import matplotlib.pyplot as plt
     import matplotlib.font_manager as fm
     fm.fontManager.addfont('/path/to/mex/simhei.ttf')
     font_size=12  
     # plt.rcParams['font.family'] = ['sans-serif']
     plt.rcParams['font.sans-serif'] = ['SimHei'] #散点图标签可以显示中文    plt.figure(figsize=(13, 9))
     # 使用内置字体名称初始化
     plt.text(0.5, 0.5, 'this is 文本')
     # 验证font_properties参数
     plt.annotate('this is 注解', (0.1, 0.1))
     plt.plot([0,1],[1,0],label='this is图例' )
     # 验证fontproperties参数
     plt.title("this is 标题")
     plt.xlabel("this is x轴")
     plt.ylabel("this is y轴")
     plt.legend()  # 显示图例
     plt.grid()
     plt.show()
 plot_with_chinese()

效果如下

解决matplotlib中文乱码最简单方案_matplotlib_02