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

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

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

相关推荐
-To be number.wan1 天前
Python数据分析:Matplotlib 绘图练习
python·数据分析·matplotlib
muddjsv1 天前
科研级置信区间(CI)曲线可视化实战(Matplotlib)
matplotlib
muddjsv2 天前
Matplotlib 科研级颜色映射(Colormap)可视化实战
matplotlib
muddjsv5 天前
Matplotlib 饼图与环形图:占比类数据可视化方法
信息可视化·matplotlib
如果曾经拥有7 天前
matplotlib - 绘制ROC曲线95%置信区间
matplotlib
muddjsv7 天前
了解Matplotlib 核心基础:环境配置 + 三层架构 + 绘图流程
matplotlib
醉舞经阁半卷书18 天前
Matplotlib从入门到精通
python·数据分析·matplotlib
葱明撅腚9 天前
seaborn绘图(下)
python·matplotlib·可视化·seaborn·图表绘制
_Soy_Milk10 天前
【算法工程师】—— Python 数据分析
python·数据分析·numpy·pandas·matplotlib
智航GIS21 天前
11.2 Matplotlib 数据可视化教程
python·信息可视化·matplotlib