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)
相关推荐
zzzzzz3107 小时前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode7 小时前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
A小辣椒2 天前
TShark:Wireshark CLI 功能
linux
A小辣椒2 天前
TShark:基础知识
linux
AlfredZhao2 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao3 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334663 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪3 天前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠4 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
bush44 天前
嵌入式linux学习记录十四、术语
linux·嵌入式