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)
相关推荐
遇见火星2 分钟前
Linux 命令篇:df、du、fdisk 磁盘管理
linux·运维·服务器·df·du·fdisk
凌~风4 分钟前
013-计算机操作系统实验报告之Linux命令!
linux·计算机操作系统·实验报告
牛奶咖啡139 分钟前
shell脚本编程(七)
linux·shell脚本编程·列表for循环·列表for循环的多种示例·for循环的break用法·for循环continue用法·c语言型for循环
南烟斋..1 小时前
Linux系统编程核心知识指南
linux·算法
森旺电子1 小时前
Linux指令快速记忆
linux·运维·服务器
weixin_516023072 小时前
电子阻止本领 electronic stopping power
linux
开开心心就好2 小时前
免费无广告卸载工具,轻便安全适配全用户
linux·运维·服务器·网络·安全·启发式算法·1024程序员节
硬核子牙2 小时前
ebpf检测Linux系统要来了
linux
↘"LYong2 小时前
Centos升级Redis(7.4.1 ---> 7.4.6)
linux·redis
bedynamic2 小时前
Ubuntu虚拟机磁盘空间不足解决方案
linux·ubuntu