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

这里下载下来的是.rar文件, 若系统无rar和unrar, 则以apt-get下载之, 之后将其解压:
rar+unrar使用参考链接

unrar x simheittf.rar
搬运windows中的

C:/Windows/fonts/里面挑选

放至Ubuntu中的路径

/usr/share/fonts/truetype

转载于:https://www.cnblogs.com/ZhengPeng7/p/8823956.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值