matplotlib显示中文字体


代码运行时生效

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontManager

fm = FontManager()
fonts = set(f.name for f in fm.ttflist)
for font in fonts:
    print(font)

plt.rcParams['font.family'] = 'sans-serif'  # 设置可以参考第二篇
plt.rcParams['font.sans-serif'] = ['Songti SC', 'STFangsong', 'STHeiti', 'BiauKai']  # 从fonts找出的一些中文字体

可能涉及系统目录(macOS Mojave 10.14.6)

$ open /Library/Fonts/
$ open ~/.matplotlib

$ python
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
>>> print(matplotlib.__path__)

需要注意的是,conda创建的不同环境下相同包的不同路径。

参考

mac下python matplotlib中文乱码解决方案(亲测可用)!! | 瓜而不皮 | CSDN
matplotlib入门--font | 杨帆 | 知乎
常用字体中英文对照 | 曾昌 | CSDN
如何优雅的选择字体(font-family) | koreyhan | segmentfault


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM