matplotlib 图标显示中文

matplotlib 显示中文

Method_1:

# 添上:
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

Method_2:

先定义myfont变量, 使其获取某个本地的字体, 然后在需要显示相应字体的函数中使用fontproperties参数, 赋值myfont即可:

from matplotlib.font_manager import FontProperties
myfont = FontProperties(fname='/usr/share/fonts/truetype/simhei.ttf',
                            size=20)
...
plt.title(SOME_STR, fontproperties=myfont)

Ubuntu中缺少中文字体:

网上下

字体下载网站
下载SimHei入口1
下载SimHei入口2

搬运windows中的

C:/Windows/fonts/里面挑选

放至Ubuntu中的路径

/usr/share/fonts/truetype

posted @ 2017-08-27 15:13  默盒  阅读(292)  评论(0编辑  收藏  举报