查找适用于matplotlib的中文字体名称与实际文件名对应关系的方法
问题来源
如何在matplotlib
中使用中文字体是老问题了,相关文章非常多。
前几天有人问我如何知道中文字体名称和实际文件的对应关系
时,才想起来原来没思考过这个问题,只能让他记住字体与文件的对应关系或者去fonts
目录查看。
难道真的就没有稍微自动化、智能化的查看支持matplotlib
的字体名称与文件的对应关系的方法?
问题解决步骤
matplotlib
与字体相关的模块是font_manager
,观察源码font_manager.py
可知:
1. matplotlib支持哪种类型的字体?
def get_fontext_synonyms(fontext): """ return a list of file extensions extensions that are synonyms for the given file extension *fileext*. """ return { 'afm': ['afm'], 'otf': ['otf', 'ttc', 'ttf'], 'ttc': ['otf', 'ttc', 'ttf'], 'ttf': ['otf', 'ttc', 'ttf'], }[fontext]
由此可知matplotlib
只支持ttf
和afm
字体。
- ‘ttf': truetype and opentype fonts (.ttf, .ttc, .otf)
- ‘afm': adobe font metrics (.afm)
2. matplotlib如何查找系统字体?
findsystemfonts
模块函数的作用是查找系统字体。def findsystemfonts(fontpaths=none, fontext='ttf'): -->list
参数fontext
默认值为'ttf'
,另外还支持值'afm'
。
参数fontpaths
默认值是none
。
对于fontpaths
有两种种情况。
fontpaths
为none
函数会判断操作系统,如果是windows,调用函数win32installedfonts
,如果不是windows,调用函数get_fontconfig_fonts
。
对于windows,函数win32installedfonts
到以下路径查找。
# os font paths msfolders = \ r'software\microsoft\windows\currentversion\explorer\shell folders' msfontdirectories = [ r'software\microsoft\windows nt\currentversion\fonts', r'software\microsoft\windows\currentversion\fonts'] msuserfontdirectories = [ str(path.home() / 'appdata/local/microsoft/windows/fonts'), str(path.home() / 'appdata/roaming/microsoft/windows/fonts'), ]
对于非windows
操作系统,函数get_fontconfig_fonts
主要依托fontconfig
包(即fc-list
命令)查找字体,要求fontconfig>=2.7
。
fontpaths
不为none
当fontpaths
不为none
时,通过list_fonts()
函数查找字体。list_fonts()
函数其实一个通用的按路径、扩展名递归遍历文件路径的函数。
def list_fonts(directory, extensions): """ return a list of all fonts matching any of the extensions, found recursively under the directory. """ extensions = ["." + ext for ext in extensions] return [os.path.join(dirpath, filename) # os.walk ignores access errors, unlike path.glob. for dirpath, _, filenames in os.walk(directory) for filename in filenames if path(filename).suffix.lower() in extensions]
3.matplotlib如何查找matplotlib自带字体?
安装matplotlib
时,会在site-packages\matplotlib\mpl-data\fonts
目录放置一系列字体。
通过源码可知fonts
目录下有'ttf', 'afm', 'pdfcorefonts'
3个子目录。
paths = [cbook._get_data_path('fonts', subdir) for subdir in ['ttf', 'afm', 'pdfcorefonts']]
in [1]: import matplotlib.cbook as cbook in [2]: paths = [cbook._get_data_path('fonts', subdir) for subdir in ['ttf', 'afm', 'pdfcorefonts']] in [3]: paths out[4]: [windowspath('c:/users/administrator/appdata/local/programs/python/python37/lib/site-packages/matplotlib/mpl-data/fonts/ttf'), windowspath('c:/users/administrator/appdata/local/programs/python/python37/lib/site-packages/matplotlib/mpl-data/fonts/afm'), windowspath('c:/users/administrator/appdata/local/programs/python/python37/lib/site-packages/matplotlib/mpl-data/fonts/pdfcorefonts')]
4.matplotlib如何生成字体列表?
fontmanager
类是matplotlib
管理字体的重要类,是一个单例类。fontmanager
实例在构造后会创建一个ttf
字体列表和一个afm
字体列表,并会缓存他们的字体属性。
下面简单看看ttflist
、afmlist
列表的元素的属性。
in [1]: import matplotlib.font_manager as mf in [2]: ttflist=mf.fontmanager().ttflist in [3]: vars(ttflist[0]) out[3]: {'fname': 'c:\\users\\administrator\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\dejavusansmono-boldoblique.ttf', 'name': 'dejavu sans mono', 'style': 'oblique', 'variant': 'normal', 'weight': 700, 'stretch': 'normal', 'size': 'scalable'} in [4]: len(ttflist) out[4]: 252 in [5]: afmlist=mf.fontmanager().afmlist in [6]: vars(afmlist[0]) out[6]: {'fname': 'c:\\users\\administrator\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\afm\\pagko8a.afm', 'name': 'itc avant garde gothic', 'style': 'italic', 'variant': 'normal', 'weight': 'book', 'stretch': 'normal', 'size': 'scalable'} in [7]: len(afmlist) out[7]: 60
5.matplotlib的字体属性缓存在哪里?
前面了解到matplotlib
会缓存字体属性那在什么位置呢?
根据源码可知,字体缓存的所在目录是.matplotlib
,缓存文件是fontlist-v330.json
(文件名与版本有关)。在某些老版本的matplotlib
中字体缓存文件名是fontlist.cache
。
_fmcache = os.path.join( mpl.get_cachedir(), 'fontlist-v{}.json'.format(fontmanager.__version__))
in [1]: import matplotlib in [2]: matplotlib.get_cachedir() out[2]: 'c:\\users\\administrator\\.matplotlib'
6. 怎么知道哪些字体是中文字体?
虽然在前面已经知道matplotlib
会把系统字体和自带字体信息存放在ttflist
和afmlist
中,但是在这些字体信息中也不容易确定哪些是中文字体。
通过资料查找有3种方法:
查看windows的fonts
系统目录中显示的字体名称和文件名属性。这种方法效率太低!
通过注册表项[hkey_local_machine\software\microsoft\windows nt\currentversion\fonts]
查看字体名和字体文件名称映射。这种方法一些系统字体仍然看不到汉字名称。
根据第1种方法想到了去查字体文件的元数据,python相关的库有两个:fonttools
,作者是老爹guido的弟弟just van rossum
;ttfquery
,基于fonttools
的ttf包,只能查看ttf
文件而且最后更新日期是2012年。
ttfqery
项目地址https://pypi.org/project/ttfquery/
源码中有些小问题,源码不算复杂,直接修改。
import sys from fonttools.ttlib import ttfont from fonttools.ttlib.ttcollection import ttcollection unicode_encodings = {0: 'unicode 1.0 semantics', 1: 'unicode 1.1 semantics', 2: 'unicode 1.1 semantics', 3: 'unicode 2.0 and onwards semantics, unicode bmp only (cmap subtable formats 0, 4, 6).', 4: 'unicode 2.0 and onwards semantics, unicode full repertoire (cmap subtable formats 0, 4, 6, 10, 12).', 5: 'unicode variation sequences (cmap subtable format 14).', 6: 'unicode variation sequences (cmap subtable format 14).'} windows_encodings = {0: 'symbol', 1: 'unicode bmp(ucs-2)', 2: 'shiftjis', 3: 'prc', 4: 'big5', 5: 'wansung', 6: 'johab', 7: 'reserved', 8: 'reserved', 9: 'reserved', 10: 'unicode ucs-4'} windows_languages = {1025: 'arabic/saudi arabia', 1026: 'bulgarian/bulgaria', 1027: 'catalan/catalan', 1028: 'chinese/*', 1029: 'czech/czech republic', 1030: 'danish/denmark', 1031: 'german/germany', 1032: 'greek/greece', 1033: 'english/united states', 1034: 'spanish (traditional sort)/spain', 1035: 'finnish/finland', 1036: 'french/france', 1037: 'hebrew/israel', 1038: 'hungarian/hungary', 1039: 'icelandic/iceland', 1040: 'italian/italy', 1041: 'japanese/japan', 1042: 'korean/korea', 1043: 'dutch/netherlands', 1044: 'norwegian (bokmal)/norway', 1045: 'polish/poland', 1046: 'portuguese/brazil', 1047: 'romansh/switzerland', 1048: 'romanian/romania', 1049: 'russian/russia', 1050: 'croatian/croatia', 1051: 'slovak/slovakia', 1052: 'albanian/albania', 1053: 'swedish/sweden', 1054: 'thai/thailand', 1055: 'turkish/turkey', 1056: 'urdu/islamic republic of pakistan', 1057: 'indonesian/indonesia', 1058: 'ukrainian/ukraine', 1059: 'belarusian/belarus', 1060: 'slovenian/slovenia', 1061: 'estonian/estonia', 1062: 'latvian/latvia', 1063: 'lithuanian/lithuania', 1064: 'tajik (cyrillic)/tajikistan', 1066: 'vietnamese/vietnam', 1067: 'armenian/armenia', 1068: 'azeri (latin)/azerbaijan', 1069: 'basque/basque', 1070: 'upper sorbian/germany', 1071: 'macedonian (fyrom)/former yugoslav republic of macedonia', 1074: 'setswana/south africa', 1076: 'isixhosa/south africa', 1077: 'isizulu/south africa', 1078: 'afrikaans/south africa', 1079: 'georgian/georgia', 1080: 'faroese/faroe islands', 1081: 'hindi/india', 1082: 'maltese/malta', 1083: 'sami (northern)/norway', 1086: 'malay/malaysia', 1087: 'kazakh/kazakhstan', 1088: 'kyrgyz/kyrgyzstan', 1089: 'kiswahili/kenya', 1090: 'turkmen/turkmenistan', 1091: 'uzbek (latin)/uzbekistan', 1092: 'tatar/russia', 1093: 'bengali/india', 1094: 'punjabi/india', 1095: 'gujarati/india', 1096: 'odia (formerly oriya)/india', 1097: 'tamil/india', 1098: 'telugu/india', 1099: 'kannada/india', 1100: 'malayalam/india', 1101: 'assamese/india', 1102: 'marathi/india', 1103: 'sanskrit/india', 1104: '*n (cyrillic)/*', 1105: '*/prc', 1106: 'welsh/united kingdom', 1107: 'khmer/cambodia', 1108: 'lao/lao p.d.r.', 1110: 'galician/galician', 1111: 'konkani/india', 1114: 'syriac/syria', 1115: 'sinhala/sri lanka', 1117: 'inuktitut/canada', 1118: 'amharic/ethiopia', 1121: 'nepali/nepal', 1122: 'frisian/netherlands', 1123: 'pashto/afghanistan', 1124: 'filipino/philippines', 1125: 'divehi/maldives', 1128: 'hausa (latin)/nigeria', 1130: 'yoruba/nigeria', 1131: 'quechua/bolivia', 1132: 'sesotho sa leboa/south africa', 1133: 'bashkir/russia', 1134: 'luxembourgish/luxembourg', 1135: 'greenlandic/greenland', 1136: 'igbo/nigeria', 1144: 'yi/prc', 1146: 'mapudungun/chile', 1148: 'mohawk/mohawk', 1150: 'breton/france', 1152: 'uighur/prc', 1153: 'maori/new zealand', 1154: 'occitan/france', 1155: 'corsican/france', 1156: 'alsatian/france', 1157: 'yakut/russia', 1158: "k'iche/guatemala", 1159: 'kinyarwanda/rwanda', 1160: 'wolof/senegal', 1164: 'dari/afghanistan', 2049: 'arabic/iraq', 2052: "chinese/people's *", 2055: 'german/switzerland', 2057: 'english/united kingdom', 2058: 'spanish/mexico', 2060: 'french/belgium', 2064: 'italian/switzerland', 2067: 'dutch/belgium', 2068: 'norwegian (nynorsk)/norway', 2070: 'portuguese/portugal', 2074: 'serbian (latin)/serbia', 2077: 'sweden/finland', 2092: 'azeri (cyrillic)/azerbaijan', 2094: 'lower sorbian/germany', 2107: 'sami (northern)/sweden', 2108: 'irish/ireland', 2110: 'malay/brunei darussalam', 2115: 'uzbek (cyrillic)/uzbekistan', 2117: 'bengali/bangladesh', 2128: "*n (traditional)/people's *", 2141: 'inuktitut (latin)/canada', 2143: 'tamazight (latin)/algeria', 2155: 'quechua/ecuador', 3073: 'arabic/egypt', 3076: 'chinese/* s.a.r.', 3079: 'german/austria', 3081: 'english/australia', 3082: 'spanish (modern sort)/spain', 3084: 'french/canada', 3098: 'serbian (cyrillic)/serbia', 3131: 'sami (northern)/finland', 3179: 'quechua/peru', 4097: 'arabic/libya', 4100: 'chinese/singapore', 4103: 'german/luxembourg', 4105: 'english/canada', 4106: 'spanish/guatemala', 4108: 'french/switzerland', 4122: 'croatian (latin)/bosnia and herzegovina', 4155: 'sami (lule)/norway', 5121: 'arabic/algeria', 5124: 'chinese/macao s.a.r.', 5127: 'german/liechtenstein', 5129: 'english/new zealand', 5130: 'spanish/costa rica', 5132: 'french/luxembourg', 5146: 'bosnian (latin)/bosnia and herzegovina', 5179: 'sami (lule)/sweden', 6145: 'arabic/morocco', 6153: 'english/ireland', 6154: 'spanish/panama', 6156: 'french/principality of monaco', 6170: 'serbian (latin)/bosnia and herzegovina', 6203: 'sami (southern)/norway', 7169: 'arabic/tunisia', 7177: 'english/south africa', 7178: 'spanish/dominican republic', 7194: 'serbian (cyrillic)/bosnia and herzegovina', 7227: 'sami (southern)/sweden', 8193: 'arabic/oman', 8201: 'english/jamaica', 8202: 'spanish/venezuela', 8218: 'bosnian (cyrillic)/bosnia and herzegovina', 8251: 'sami (skolt)/finland', 9217: 'arabic/yemen', 9225: 'english/caribbean', 9226: 'spanish/colombia', 9275: 'sami (inari)/finland', 10241: 'arabic/syria', 10249: 'english/belize', 10250: 'spanish/peru', 11265: 'arabic/jordan', 11273: 'english/trinidad and tobago', 11274: 'spanish/argentina', 12289: 'arabic/lebanon', 12297: 'english/zimbabwe', 12298: 'spanish/ecuador', 13313: 'arabic/kuwait', 13321: 'english/republic of the philippines', 13322: 'spanish/chile', 14337: 'arabic/u.a.e.', 14346: 'spanish/uruguay', 15361: 'arabic/bahrain', 15370: 'spanish/paraguay', 16385: 'arabic/qatar', 16393: 'english/india', 16394: 'spanish/bolivia', 17417: 'english/malaysia', 17418: 'spanish/el salvador', 18441: 'english/singapore', 18442: 'spanish/honduras', 19466: 'spanish/nicaragua', 20490: 'spanish/puerto rico', 21514: 'spanish/united states'} macintosh_encodings = {0: 'roman', 1: 'japanese', 2: 'chinese', 3: 'korean', 4: 'arabic', 5: 'hebrew', 6: 'greek', 7: 'russian', 8: 'rsymbol', 9: 'devanagari', 10: 'gurmukhi', 11: 'gujarati', 12: 'oriya', 13: 'bengali', 14: 'tamil', 15: 'telugu', 16: 'kannada', 17: 'malayalam', 18: 'sinhalese', 19: 'burmese', 20: 'khmer', 21: 'thai', 22: 'laotian', 23: 'georgian', 24: 'armenian', 25: 'chinese', 26: '*', 27: '*n', 28: 'geez', 29: 'slavic', 30: 'vietnamese', 31: 'sindhi', 32: 'uninterpreted'} macintosh_languages = {0: 'english', 1: 'french', 2: 'german', 3: 'italian', 4: 'dutch', 5: 'swedish', 6: 'spanish', 7: 'danish', 8: 'portuguese', 9: 'norwegian', 10: 'hebrew', 11: 'japanese', 12: 'arabic', 13: 'finnish', 14: 'inuktitut', 15: 'icelandic', 16: 'maltese', 17: 'turkish', 18: 'croatian', 19: 'chinese (traditional)', 20: 'urdu', 21: 'hindi', 22: 'thai', 23: 'korean', 24: 'lithuanian', 25: 'polish', 26: 'hungarian', 27: 'estonian', 28: 'latvian', 29: 'sami', 30: 'faroese', 31: 'farsi/persian', 32: 'russian', 33: 'chinese (simplified)', 34: 'flemish', 35: 'irish gaelic', 36: 'albanian', 37: 'romanian', 38: 'czech', 39: 'slovak', 40: 'slovenian', 41: 'yiddish', 42: 'serbian', 43: 'macedonian', 44: 'bulgarian', 45: 'ukrainian', 46: 'byelorussian', 47: 'uzbek', 48: 'kazakh', 49: 'azerbaijani (cyrillic script)', 50: 'azerbaijani (arabic script)', 51: 'armenian', 52: 'georgian', 53: 'moldavian', 54: 'kirghiz', 55: 'tajiki', 56: 'turkmen', 57: '*n (*n script)', 58: '*n (cyrillic script)', 59: 'pashto', 60: 'kurdish', 61: 'kashmiri', 62: 'sindhi', 63: '*', 64: 'nepali', 65: 'sanskrit', 66: 'marathi', 67: 'bengali', 68: 'assamese', 69: 'gujarati', 70: 'punjabi', 71: 'oriya', 72: 'malayalam', 73: 'kannada', 74: 'tamil', 75: 'telugu', 76: 'sinhalese', 77: 'burmese', 78: 'khmer', 79: 'lao', 80: 'vietnamese', 81: 'indonesian', 82: 'tagalong', 83: 'malay (roman script)', 84: 'malay (arabic script)', 85: 'amharic', 86: 'tigrinya', 87: 'galla', 88: 'somali', 89: 'swahili', 90: 'kinyarwanda/ruanda', 91: 'rundi', 92: 'nyanja/chewa', 93: 'malagasy', 94: 'esperanto', 128: 'welsh', 129: 'basque', 130: 'catalan', 131: 'latin', 132: 'quenchua', 133: 'guarani', 134: 'aymara', 135: 'tatar', 136: 'uighur', 137: 'dzongkha', 138: 'javanese (roman script)', 139: 'sundanese (roman script)', 140: 'galician', 141: 'afrikaans', 142: 'breton', 144: 'scottish gaelic', 145: 'manx gaelic', 146: 'irish gaelic (with dot above)', 147: 'tongan', 148: 'greek (polytonic)', 149: 'greenlandic', 150: 'azerbaijani (roman script)'} iso_ids = { 0: '7-bit ascii', 1: 'iso 10646', 2: 'iso 8859-1' } customs = {} platforms = {0: {'name': 'unicode', 'encodings': unicode_encodings, 'languages': unicode_encodings}, 1: {'name': 'macintosh', 'encodings': macintosh_encodings, 'languages': macintosh_languages}, 2: {'name': 'iso [deprecated]', 'encodings': iso_ids, 'languages': iso_ids}, 3: {'name': 'windows', 'encodings': windows_encodings, 'languages': windows_languages}, 4: {'name': 'custom', 'encodings': customs, 'languages': customs}} name_table = {0: 'copyright notice', 1: 'font family', 2: 'subfamily', 3: 'unique font identifier', 4: 'full font name', 5: 'version', 6: 'postscript name', 7: 'trademark', 8: 'manufacturer name', 9: 'designer', 10: 'description', 11: 'vendor url', 12: 'designer url', 13: 'license description', 14: 'license info url', 15: 'reserved', 16: 'typographic family', 17: 'typographic subfamily', 18: 'compatible full', 19: 'sample text', 20: 'postscript cid findfont name', 21: 'wws family name', 22: 'wws subfamily name', 23: 'light background pallete', 24: 'dark background pallete', 25: 'variations postscript name prefix'} encodings = { "roman": 'latin_1' } def parse_meta(font): """the main meta parsing function. thanks to fonttools library.""" data = {} for nti in font['name'].names: key = nti.nameid platform_data = platforms[nti.platformid] if platform_data['name'] == 'custom': encoding = {'id': 0, 'value': 'custom'} language = {'id': 0, 'value': 'custom'} else: encoding = {'id': nti.platencid, 'value': platform_data['encodings'].get(nti.platencid, "unknown")} language = {'id': nti.langid, 'value': platform_data['languages'].get(nti.langid, "unknown")} name_str = nti.tostr() field = name_table.get(nti.nameid, false) if not field: if 26 <= nti.nameid <= 255: field = 'reserved [{}]'.format(nti.nameid) elif 256 <= nti.nameid: field = 'font specific[{}]'.format(nti.nameid) data[key] = {"field": field, "value": name_str, "encoding": encoding, "language": language } return data def get_font_name(data, language=none): language_name = data.get(4).get('language').get('value') font_full_name = data.get(4).get('value') if language is none: return font_full_name else: if language in language_name: return font_full_name if __name__ == '__main__': from pathlib import path import matplotlib.font_manager as fm ttflist=fm.fontmanager().ttflist for f in ttflist: if path(f.fname).suffix.lower()=='.ttf': # 输出字体元数据中语言包含有中文的ttf字体 data = parse_meta(ttfont(f.fname)) out_ttf = get_font_name(data,'chinese') if out_ttf: print(f.fname,f.name,out_ttf) elif path(f.fname).suffix.lower()=='.ttc': # 输出所有ttc字体中包含的字体名称信息 ttc = ttcollection(f.fname) for ttf in ttc: ttc_data = parse_meta(ttf) out_ttc = get_font_name(ttc_data,'chinese') if out_ttc: print(f.fname,f.name,out_ttc)
ttc
文件很特殊,它是多个ttf
文件集合,常用字体宋体
、微软雅黑
等在windows10中都是ttc
文件,而且奇怪的是很多语言信息不是中文的ttc字体也可以显示中文。
c:\windows\fonts\sthupo.ttf sthupo 华文琥珀 c:\windows\fonts\mingliub.ttc mingliu-extb 細明體-extb c:\windows\fonts\mingliub.ttc mingliu-extb 新細明體-extb c:\windows\fonts\mingliub.ttc mingliu-extb 細明體_hkscs-extb c:\windows\fonts\simkai.ttf kaiti 楷体 c:\windows\fonts\stxihei.ttf stxihei 华文细黑 c:\users\administrator\appdata\local\microsoft\windows\fonts\仿宋_gb2312.ttf fangsong_gb2312 仿宋_gb2312 c:\users\administrator\appdata\local\microsoft\windows\fonts\楷体_gb2312.ttf kaiti_gb2312 楷体_gb2312 c:\windows\fonts\stxingka.ttf stxingkai 华文行楷 c:\windows\fonts\stcaiyun.ttf stcaiyun 华文彩云 c:\windows\fonts\simsun.ttc simsun 宋体 c:\windows\fonts\simsun.ttc simsun 新宋体 c:\windows\fonts\stkaiti.ttf stkaiti 华文楷体 c:\windows\fonts\msjhl.ttc microsoft jhenghei 微軟正黑體 light c:\windows\fonts\msjhl.ttc microsoft jhenghei microsoft jhenghei ui light c:\users\administrator\appdata\local\microsoft\windows\fonts\华文中宋.ttf stzhongsong 华文中宋 c:\windows\fonts\fzytk.ttf fzyaoti 方正姚体 c:\users\administrator\appdata\local\microsoft\windows\fonts\方正卡通简体.ttf fzkatong-m19s 方正卡通简体 c:\windows\fonts\simhei.ttf simhei 黑体 c:\windows\fonts\方正粗黑宋简体.ttf fzcuheisongs-b-gb 方正粗黑宋简体 c:\windows\fonts\deng.ttf dengxian 等线 c:\users\administrator\appdata\local\microsoft\windows\fonts\fzxbsjw.ttf fzxiaobiaosong-b05s 方正小标宋简体 c:\windows\fonts\dengl.ttf dengxian 等线 light c:\windows\fonts\msjh.ttc microsoft jhenghei 微軟正黑體 c:\windows\fonts\msjh.ttc microsoft jhenghei microsoft jhenghei ui c:\windows\fonts\msyh.ttc microsoft yahei 微软雅黑 c:\windows\fonts\msyh.ttc microsoft yahei microsoft yahei ui c:\windows\fonts\stfangso.ttf stfangsong 华文仿宋 c:\windows\fonts\simfang.ttf fangsong 仿宋 c:\windows\fonts\simli.ttf lisu 隶书 c:\windows\fonts\simyou.ttf youyuan 幼圆 c:\windows\fonts\stliti.ttf stliti 华文隶书 c:\windows\fonts\dengb.ttf dengxian 等线 bold c:\windows\fonts\msyhl.ttc microsoft yahei 微软雅黑 light c:\windows\fonts\msyhl.ttc microsoft yahei microsoft yahei ui light c:\windows\fonts\stsong.ttf stsong 华文宋体 c:\windows\fonts\stxinwei.ttf stxinwei 华文新魏 c:\windows\fonts\fzstk.ttf fzshuti 方正舒体
参考
https://fonttools.readthedocs.io/en/latest/ttlib/index.html
到此这篇关于查找适用于matplotlib的中文字体名称与实际文件名对应关系的方法的文章就介绍到这了,更多相关matplotlib中文字体名称与实际文件名对应内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: ArrayList的内存泄露
下一篇: 如何快速修改MySQL用户的host属性