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

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

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

相关推荐
byzh_rc3 天前
[AI工具从入门到入土] 命令行
网络·人工智能·python·深度学习·matplotlib
小何code4 天前
人工智能【第7篇】数据可视化:Matplotlib与Seaborn实战(万字长文+完整代码)
人工智能·机器学习·信息可视化·matplotlib
qq_283720059 天前
Python3 模块精讲:Matplotlib—— 数据可视化、绘图从零基础到实战精通
信息可视化·matplotlib
2401_827499999 天前
数据分析学习06(黑马)-Matplotlib
学习·数据分析·matplotlib
哈伦201913 天前
第六章 Matplotlib案例股票K线图绘制
python·matplotlib
淮北49413 天前
ubuntu22.04将mp4转换成gif
python·scrapy·flask·beautifulsoup·pyqt·matplotlib
xiaotao13118 天前
01-编程基础与数学基石:Matplotlib & Seaborn
人工智能·python·matplotlib
l1t19 天前
uv提供的cpython高版本已经解决了matplotlib无法显示图形问题
matplotlib·uv
哈伦201920 天前
第六章 Matplotlib
matplotlib·anaconda3
l1t20 天前
uv安装的cpython使用matplotlib库作图不能显示的问题起因和解决
matplotlib·uv