美文网首页
linux下matplotlib无法显示中文解决方法

linux下matplotlib无法显示中文解决方法

作者: 爱垂钓的猫 | 来源:发表于2019-04-03 18:18 被阅读0次

1.首先在deepin下安装字体

2.之后输入下端代码查看能使用的中文字体

! /usr/bin/env python

-- coding: utf-8 --

from matplotlib.font_manager import FontManager
import subprocess

fm = FontManager()
mat_fonts = set(f.name for f in fm.ttflist)

print(mat_fonts)

output = subprocess.check_output('fc-list :lang=zh -f "%{family}\n"', shell=True)

print( '' * 10, '系统可用的中文字体', '' * 10)

print (output)

zh_fonts = set(f.split(',', 1)[0] for f in output.decode('utf-8').split('\n'))
available = mat_fonts & zh_fonts
print ('' * 10, '可用的字体', '' * 10)
for f in available:
print (f)

3.将能使用的中文字体放在
home/anaconda/lib/python3.7/dist-packages/matplotlib/mpl-data/fonts/ttf下

4.修改matplotlib配置文件:
~/anaconda/lib/python3.7/dist-packages/matplotlib/mpl-data/matplotlibrc
删除font.family和font.sans-serif两行前的#,并在font.sans-serif后添加中文字体的名字, ...(其余不变)

5.删除~/.cache/matplotlib下文件fontList.py3k.cache

6.重启python

相关文章

网友评论

      本文标题:linux下matplotlib无法显示中文解决方法

      本文链接:https://www.haomeiwen.com/subject/jattiqtx.html