問(wèn)題:matplotlib不能渲染中文
想設(shè)定為中文字體,網(wǎng)上搜索的方法幾乎都是下面這樣,已經(jīng)把字體拷貝到了程序目錄下了,然而并沒(méi)有生效
plt.rcParams [ font.sans-serif'] = ['SimHei.ttf']
解決
設(shè)置字體路徑和字體名
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'
熱門工具 換一換
