當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python matplotlib FontManager用法及代碼示例

本文簡要介紹 python 語言中 matplotlib.font_manager.FontManager 的用法。

用法

class matplotlib.font_manager.FontManager(size=None, weight='normal')

基礎: object

導入時, FontManager 單例實例創建 ttf 和 afm 字體列表並緩存它們的 FontPropertiesFontManager.findfont 方法執行最近鄰搜索以查找與規範最匹配的字體。如果找不到足夠好的匹配項,則返回默認字體。

使用 FontManager.addfont 方法添加的字體不會保留在緩存中;因此,每次導入 Matplotlib 時都需要調用addfont。僅當無法通過其他方式在操作係統上安裝字體時才應使用此方法。

注意

必須在全局 FontManager 實例上調用 FontManager.addfont 方法。

示例用法:

import matplotlib.pyplot as plt
from matplotlib import font_manager

font_dirs = ["/resources/fonts"]  # The path to the custom font file.
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)

for font_file in font_files:
    font_manager.fontManager.addfont(font_file)

相關用法


注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.font_manager.FontManager。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。