問題:matplotlib不能渲染中文
想設定為中文字體,網上搜索的方法幾乎都是下面這樣,已經把字體拷貝到了程序目錄下了,然而並沒有生效
plt.rcParams [ font.sans-serif'] = ['SimHei.ttf']
解決
設置字體路徑和字體名
import matplotlib.font_manager as font_manager
from matplotlib import pyplot as plt
font_dirs = ['你的字體路徑']
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
font_list = font_manager.createFontList(font_files)
font_manager.fontManager.ttflist.extend(font_list)
plt.rcParams['font.family'] = '你的字體名
下面是本人用的代碼
import matplotlib.font_manager as font_manager
font_dirs = ['/Users/chenqionghe/me/project/python/python-test/jupyter/myfonts']
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
font_list = font_manager.createFontList(font_files)
font_manager.fontManager.ttflist.extend(font_list)
plt.rcParams['font.family'] = 'SimHei'
