解决Linux上的jupyterlab缺少SimHei的问题(适用于所有Linux系统)(2023)

简单的说,由于没有对应字体,导入

import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.sans-serif'] = ['SimHei'] 
plt.rcParams['axes.unicode_minus'] = False 

报错

findfont: Font family ‘SimHei’ not found

此处需要执行

import os
import shutil
import urllib.request
import matplotlib

# 设置字体文件的URL和目标文件路径
font_url = "https://github.com/StellarCN/scp_zh/raw/master/fonts/SimHei.ttf"
target_font_path = os.path.join(matplotlib.get_data_path(), "fonts/ttf/SimHei.ttf")

# 下载字体文件
urllib.request.urlretrieve(font_url, target_font_path)

# 找到matplotlibrc文件的路径
matplotlibrc_path = matplotlib.matplotlib_fname()
# 获取matplotlibrc文件所在的文件夹路径
matplotlibrc_dir = os.path.dirname(matplotlibrc_path)

# 找到fonts/ttf目录的路径
fonts_dir = os.path.join(matplotlib.get_data_path(), "fonts/ttf")

# 删除缓存文件夹中的内容
cache_dir = matplotlib.get_cachedir()
shutil.rmtree(cache_dir,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值