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

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

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

相关推荐
开发者小天3 天前
python安装 Matplotlib 库 安装 Seaborn 库
开发语言·python·matplotlib
kong79069288 天前
Python核心语法-Matplotlib简介
开发语言·python·matplotlib
励ℳ12 天前
生信绘图-Matplotlib绘制云雨图(小提琴图+箱线图+散点)
matplotlib
Fleshy数模18 天前
数据“整容”术:Pandas+Matplotlib让你的数据会说话
pandas·matplotlib
语文天才高斯18 天前
Dify Sandbox 如何安装第三方库(matplotlib / numpy / pandas 通用方法)
人工智能·chatgpt·numpy·pandas·matplotlib
pchaoda22 天前
RSI与布林带技术指标实战
python·matplotlib·量化
啊阿狸不会拉杆22 天前
《机器学习导论》第 5 章-多元方法
人工智能·python·算法·机器学习·numpy·matplotlib·多元方法
砚边数影23 天前
数据可视化入门:Matplotlib 基础语法与折线图绘制
数据库·信息可视化·matplotlib·数据可视化·kingbase·数据库平替用金仓·金仓数据库
pchaoda23 天前
基本面因子计算入门
python·matplotlib·量化
铁手飞鹰23 天前
[深度学习]常用的库与操作
人工智能·pytorch·python·深度学习·numpy·scikit-learn·matplotlib