jupyter怎么装matplotlib (matplotlib字体粗细不能调整)

教学视频地址:https://www.ixigua.com/7296027092624343591

参考:https://blog.csdn.net/CSDN__SMART/article/details/129967190

1、在Windows环境下*载下**相应字体

用SimHei字体为例,现在下面的网址中*载下**该字体到本地电脑

http://www.1473.cn/Pages/Download.htm?id=22dd72df-3b5b-fcf5-089f-5bbaa6f0b601

2、确定字体文件路径

可以在python编译器中输入下面两行代码即可找到该文件的位置

import matplotlib

matplotlib.matplotlib_fname()

输出见下图

jupyterhub作用,jupyternotebook如何下载matplotlib模块

从输出可以看出我的参考路径为

/home/usestudio/modules/anaconda3/envs/nodejs/lib/python3.9/site-packages/matplotlib/mpl-data/matplotlibrc

3、在X-shell(或者其他Linux服务器远程终端)中上传matplotlibrc文件,

如下图,通过X-ftp(Windows与Linux服务器传输文件的工具)传输到Linux服务器相应目录中。

jupyterhub作用,jupyternotebook如何下载matplotlib模块

/root/miniconda3/envs/rapids-23.02/lib/python3.10/site-packages/matplotlib/mpl-data/fonts/ttf

这是放置文件的位置mpl-data/fonts/ttf

4、在X-shell中输入下面一行命令

vi /home/usestudio/modules/anaconda3/envs/nodejs/lib/python3.9/site-packages/matplotlib/mpl-data/matplotlibrc

就会出现一个下面的界面,我截取了一部分

jupyterhub作用,jupyternotebook如何下载matplotlib模块

然后找到下图红色方框圈住的位置

jupyterhub作用,jupyternotebook如何下载matplotlib模块

先将三个红色方框圈住部分的注释去掉,然后在font.serif和font.sans-serif的冒号后面添加上*载下**的字体名字,注意一定要看清名字大小写,最好复制粘贴过来 ,编辑参考见下图。

jupyterhub作用,jupyternotebook如何下载matplotlib模块

然后找到axes.unicode_minus开头的一行,将其注释去掉,且将其后面的True更改为False即可,具体如下图。

jupyterhub作用,jupyternotebook如何下载matplotlib模块

然后按键esc进入文件命令模式,输入:wq,即可保存文件并退出。

5、清除matplotlibrc缓存文件

在X-shell中输入下面两行命令

cd ~/.cache

rm -rf matplotlib

清除掉在修改matplotlibrc配置文件之前的缓存文件。

6、重新打开JupyterHub

进入JupyterHub编程界面jupter.1473.cn

单击重启内核按钮

jupyterhub作用,jupyternotebook如何下载matplotlib模块

然后再重新运行画图的python代码,中文就可以识别啦!!!附上效果图

jupyterhub作用,jupyternotebook如何下载matplotlib模块

也可以利用输入python代码的形式确认字体有没有被成功导入到Jupyter Lab中,在python编译器中输入

from matplotlib import font_manager

a = sorted([f.name for f in font_manager.fontManager.ttflist])

for i in a:

print(i)

在输出中如果看到simhei字体即成功导入,也就可以识别啦!

jupyterhub作用,jupyternotebook如何下载matplotlib模块