(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 天前
Matplotlib入门教程(十三):imshow() 详解——灰度图、彩色图、热力图与矩阵可视化
线性代数·矩阵·matplotlib
小小龙学IT1 天前
Python Matplotlib 数据可视化库深度解析
python·信息可视化·matplotlib
烂蜻蜓3 天前
Matplotlib入门教程(十一):饼图详解——pie() 函数与占比可视化
matplotlib
烂蜻蜓3 天前
Matplotlib入门教程(十):柱形图详解——bar() 与 barh() 函数完全指南
matplotlib
ctlover7 天前
Matplotlib
matplotlib
for_ever_love__9 天前
Matplotlib——把训练曲线和分布画出来
matplotlib·数据可视化·大模型开发·训练曲线
茶栀(*´I`*)15 天前
【Python数据可视化】Matplotlib从零到精通:图表核心解剖、多子图布局与三大经典图表实战
python·信息可视化·matplotlib
jzshmyt1 个月前
我用 Python 从零“生成“了一个宇宙,然后让它观察自己(v14)
人工智能·pytorch·python·numpy·matplotlib·空间计算·scipy
小葱炖豆腐1 个月前
python绘制excel折线图
python·excel·numpy·pandas·matplotlib
七灵微1 个月前
【AI】代码实战- 基于时间序列的轴承检测1
人工智能·机器学习·ai·pandas·matplotlib