(Mac上)使用Python进行matplotlib 画图时,中文显示不出来

【问题描述】

①报错确缺失字体:

②使用matplotlib画图,中文字体显示不出来

【问题思考】

在网上搜了好多,关于使用python进行matplotlib画图字体显示不出来的,但是我试用了下,对我来说都没有。有些仅使用于windows系统,某些博主还起标题适用于mac,瞎扯。

【解决办法】:

①首先查看下mac里面的使用于matplotlib画图有那些字体呢。

python 复制代码
# 查看matplotlib中的字体有哪些
from matplotlib.font_manager import FontManager
mpl_fonts = set(f.name for f in FontManager().ttflist)
print('all font list get from matplotlib.font_manager:')
for font in sorted(mpl_fonts):
    print('\t' + font)

②选择1-2个自己熟悉的字体使用即可。

python 复制代码
import matplotlib.pyplot as plt
plt.rc("font", family='PingFang HK')   # 选择自己想要的字体就行

③运行后,字体就可以显示啦。

噢耶,可以咯,继续学习!!!

相关推荐
HuashuiMu花水木20 小时前
Matplotlib笔记4----------图像处理
图像处理·笔记·matplotlib
程序员阿超的博客2 天前
Python 数据分析与机器学习入门 (五):Matplotlib 数据可视化基础
python·信息可视化·数据分析·matplotlib·数据可视化·python教程·pyplot
音程14 天前
Matplotlib绘制矩阵图,plt.matshow/imshow 与 ax.pcolor(pcolormesh)方法的使用
matplotlib
搏博15 天前
基于Python、tkinter、sqlite3 和matplotlib的校园书店管理系统
python·信息可视化·sqlite·matplotlib
勤奋的知更鸟17 天前
Matplotlib 绘图库使用技巧介绍
开发语言·python·matplotlib
@小红花18 天前
Matplotlib快速入门
matplotlib
仟濹21 天前
「Matplotlib 入门指南」 Python 数据可视化分析【数据分析全栈攻略:爬虫+处理+可视化+报告】
python·信息可视化·数据分析·matplotlib
Jay_2724 天前
cloudstudio腾讯云:matplotlib 设置中文字体
腾讯云·matplotlib
Gyoku Mint1 个月前
机器学习×第二卷:概念下篇——她不再只是模仿,而是开始决定怎么靠近你
人工智能·python·算法·机器学习·pandas·ai编程·matplotlib
搏博1 个月前
将图形可视化工具的 Python 脚本打包为 Windows 应用程序
开发语言·windows·python·matplotlib·数据可视化