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

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

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

相关推荐
Caron_xcb4 小时前
大数据——解决Matplotlib 字体不足问题(Linux\mac\windows)
大数据·linux·matplotlib
迷人的小荔枝4 天前
seaborn
matplotlib
玫瑰花店6 天前
ubuntu中解决matplotlib无法显示中文问题
linux·ubuntu·matplotlib
龙虎榜小红牛系统11 天前
Python项目源码63:病历管理系统1.0(tkinter+sqlite3+matplotlib)
python·sqlite·matplotlib
eqwaak015 天前
Matplotlib高阶技术全景解析(续):动态交互、三维可视化与性能优化
开发语言·python·语言模型·性能优化·交互·matplotlib
T0uken16 天前
【Python】Matplotlib:立体永生花绘制
开发语言·python·matplotlib
captain_keating17 天前
使用matplotlib绘制Raincloud图/云雨图/柱状图/小提琴图
python·matplotlib
YiSLWLL19 天前
使用Tauri 2.3.1+Leptos 0.7.8开发桌面小程序汇总
python·rust·sqlite·matplotlib·visual studio code
满怀101521 天前
【Python进阶】数据可视化:Matplotlib从入门到实战
python·信息可视化·数据分析·matplotlib·数据可视化
是一只努力的小菜鸡啦23 天前
Matplotlib的应用
matplotlib