(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')   # 选择自己想要的字体就行

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

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

相关推荐
星辰徐哥1 天前
Python AI基础:Matplotlib与Seaborn数据可视化
人工智能·python·matplotlib
斐夷所非1 天前
Python Matplotlib | 基础绘图、复杂函数图与三维图
matplotlib
恣艺5 天前
解决 PyCharm 2024.1+ matplotlib 图表显示异常:Plots 工具窗口空白 / tostring_rgb 报错
ide·pycharm·matplotlib
是上好佳佳佳呀6 天前
【数据分析|Day02】Matplotlib 数据可视化笔记
笔记·matplotlib
ice8130331817 天前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib
北暮城南9 天前
使用 Claude Code 高效实现图像边缘检测:多算法对比与工程实践
python·opencv·numpy·matplotlib·边缘检测·claude code
red2brick10 天前
【使用PyQt6与Matplotlib编写交互式生成一元二次函数图形程序】
matplotlib
DogDaoDao13 天前
OpenCV 踩坑全指南
图像处理·人工智能·python·opencv·计算机视觉·matplotlib·rgb
电魂泡哥14 天前
Matplotlib.pyplot 完全入门指南
信息可视化·matplotlib
十年之少14 天前
matplotlib 与 PyQt5 结合使用——PyQt5
matplotlib·pyqt5