admin管理员组

文章数量:1594754

Ubuntu安装中文字体&解决Jupyter中文字体乱码显示问题

import matplotlib.pyplot as plt

plt.title('中文')
plt.figure()

0 查看Ubuntu字体目录

!ls /usr/share/fonts/

1 通过apt-get安装

step1: 安装文泉驿-正黑字体

!apt-get install ttf-wqy-zenhei -y

step2: 查看是否安装成功

!fc-list :lang=zh

2 自己下载字体安装

step1: 下载字体并解压

!wget http://www.mycode/wp-content/uploads/2015/07/YaHeiConsolas.tar.gz

!tar -zxvf YaHeiConsolas.tar.gz

step2: 创建vista目录 & 字体复制到该目录下

!mkdir -p /usr/share/fonts/vista

!cp YaHeiConsolas.ttf /usr/share/fonts/vista/

查看是否复制成功

!ls /usr/share/fonts/vista/

step3: 安装字体

!cd /usr/share/fonts/vista/

!mkfontscale && mkfontdir && fc-cache -fv

step4: 查看是否安装成功

!fc-list :lang=zh

3 测试能否显示

/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font_set = FontProperties(fname=r"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc", size=20) 

plt.title(u'中文',fontproperties=font_set)
plt.figure()


/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font_set = FontProperties(fname=r"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc", size=20) 

plt.title(u'中文',fontproperties=font_set)
plt.figure()

本文标签: 中文字体乱码Ubuntujupyteramp