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

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

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

相关推荐
你想知道什么?12 小时前
Matplotlib学习笔记
笔记·学习·matplotlib
风流 少年4 天前
数据可视化:matplotlib、pyecharts、panda、seaborn
数据挖掘·数据分析·matplotlib
fai厅的秃头姐!4 天前
Matplotlib
matplotlib
许彰午7 天前
78_Python数据可视化matplotlib
python·信息可视化·matplotlib
尘中远9 天前
【Qwt 7.0 系列】总体架构解析 —— 从单体到三库模块化的演进
qt·matplotlib·绘图·qwt·科学绘图
2501_9423895510 天前
AI才女”罗福莉加盟小米
matplotlib·sublime text·广度优先·gunicorn
留白_1 个月前
Matplotlib绘图
信息可视化·数据分析·matplotlib
MATLAB代码顾问1 个月前
Python Matplotlib数据可视化实战指南
python·信息可视化·matplotlib
星辰徐哥1 个月前
Python AI基础:Matplotlib与Seaborn数据可视化
人工智能·python·matplotlib
斐夷所非1 个月前
Python Matplotlib | 基础绘图、复杂函数图与三维图
matplotlib