在用python的时候经常会遇到乱码问题
1. 注释乱码问题
在代码的最上面添加:
# -*- coding: utf-8 -*-
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)
output = subprocess.check_output(
'fc-list :lang=zh -f "%{family}\n"', shell=True)