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

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

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

相关推荐
Gyoku Mint12 小时前
机器学习×第二卷:概念下篇——她不再只是模仿,而是开始决定怎么靠近你
人工智能·python·算法·机器学习·pandas·ai编程·matplotlib
搏博2 天前
将图形可视化工具的 Python 脚本打包为 Windows 应用程序
开发语言·windows·python·matplotlib·数据可视化
Code_流苏5 天前
Python趣学篇:交互式词云生成器(jieba + Tkinter + WordCloud等)
python·pillow·matplotlib·tkinter·wordcloud·jieba分词·词云生成器
AndrewHZ7 天前
【图像处理入门】2. Python中OpenCV与Matplotlib的图像操作指南
图像处理·python·opencv·计算机视觉·matplotlib·图像操作
无闻墨客8 天前
数据可视化--使用matplotlib绘制高级图表
python·机器学习·信息可视化·matplotlib·可视化·数据可视化
Echo-J9 天前
数据可视化(第4、5、6次课)
python·信息可视化·matplotlib·数据可视化
ayas1231911 天前
numpy与matplotlib学习——数据可视化入门
学习·numpy·matplotlib
zhangfeng113312 天前
Python 和 matplotlib 保存图像时,确保图像的分辨率和像素符合特定要求(如 64x64),批量保存 不溢出内存
开发语言·python·matplotlib
李昊哲小课15 天前
matplotlib基本绘图
人工智能·数据分析·matplotlib·数据可视化·pyecharts·seaborn
云攀登者-望正茂15 天前
如何在Mac 上使用Python Matplotlib
python·macos·matplotlib