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

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

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

相关推荐
MediaTea1 天前
Matplotlib 常用函数手册
matplotlib
badhope6 天前
Matplotlib实战30例:全类型图表代码库
人工智能·python·plotly·github·matplotlib
badhope6 天前
最小二乘与最速下降法实战解析
人工智能·机器学习·plotly·github·matplotlib
badhope7 天前
Docker入门到实战全攻略
linux·python·docker·github·matplotlib
李昊哲小课8 天前
matplotlib多子图与复杂布局实战
python·数据分析·matplotlib·数据可视化
李昊哲小课10 天前
matplotlib_tutorial
数据分析·matplotlib·数据可视化
byzh_rc11 天前
[AI工具从入门到入土] matplotlib
人工智能·matplotlib
李昊哲小课12 天前
国际足球比赛数据集分析报告(1872-2025)
信息可视化·数据挖掘·数据分析·pandas·matplotlib·pyecharts·seaborn
爱玩亚索的程序员12 天前
算法入门(三)学会用matplotlib画图
算法·matplotlib
瞎某某Blinder12 天前
DFT学习记录[5]电子结构分析+光学分析
linux·python·科技·学习·生活·matplotlib·帅哥