想設定爲中文字體,網上搜索的方法幾乎都是下面這樣,已經把字體拷貝到了程序目錄下了,然而並無生效python
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'] = '你的字體名
下面是本人用的代碼code
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'