在使用matplotlib画图的时候,有时候显示的中文名称是乱码,是因为matplotlib默认使用了不支持的中文编码。需要手动指定。但怎么知道支持那些字体呢?可使用下面的代码来看。
#!/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) 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.split('\n')) available = mat_fonts & zh_fonts print '*' * 10, '可用的字体', '*' * 10 for f in available: print f # ********** 可用的字体 ********* # Droid Sans Fallback
我这系统显示的只支持Droid Sans Fallback
这font.sans-serif
,那在使用的时候指定font.sans-serif
就可以正常显示了。
import matplotlib as mpl mpl.rcParams['font.sans-serif'] = ['Droid Sans Fallback']
现在就正常显示中文了。
stat -c "%a %n" file , 755, 644
ModuleNotFoundError: No module named 'MySQLdb', ...
Ubuntu18.04下使用pyenv安装python报错:BUILD FAILED (Ubun ...
dell提供了工具远程查看服务器硬件状态,可以修改硬件的参数,可以远程连接过去直接修改,就不需要 ...
启动报undefined symbol: EVP_CIPHER_CTX_cleanup错误。op ...
ubuntu开启crontab日志记录及解决No MTA installed, discardi ...
暂时还没有评论,第一个来评论吧!