Linux jupyter notebook Matplotlib 无法显示汉字

Linux jupyter notebook Matplotlib 无法显示汉字

问题:

使用matplotlib画图时, 无法显示汉字, 显示出来一堆方框

解决办法:

python 复制代码
# 1. 安装字体
sudo apt-get install fonts-wqy-zenhei  # 安装文泉驿字体

# 2. 检查字体是否安装成功
fc-list | grep "WenQuanYi Zen Hei"
fc-cache -fv

# 3. 在 jupyter notebook 中清除 matplotlib 缓存
import matplotlib
import shutil
shutil.rmtree(matplotlib.get_cachedir())

# 4. 再试试, 应该就可以正常使用了
import matplotlib.font_manager
a = sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])
for i in a:
    print(i)
相关推荐
戴为沐9 小时前
Linux内存扩容指南
linux
zylyehuo19 小时前
Linux 彻底且安全地删除文件
linux
用户805533698031 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
用户034095297911 天前
linux fcitx 5 雾凇拼音 设置在中文输入法下仍然输入英文标点
linux
Web3探索者3 天前
可视化服务器管理和传统命令行区别是什么?新手教程:Linux 运维到底该用图形界面还是 SSH 命令行?
linux·ssh
zylyehuo3 天前
Linux系统中网线与USB网络共享冲突
linux
Sokach10154 天前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
AlfredZhao5 天前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
zzzzzz3106 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode6 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏