1. 启动JupyterLab
jupyter lab --ip=0.0.0.0 --no-browser --notebook-dir=notebook
--ip=0.0.0.0监听所有ip,允许其他电脑访问
--no-brower不启动本地浏览器
--notebook-dir指定根目录
注:发现还是jupyter notebook比jupyter lab好用一些,前者允许notebook中的markdown文本引用目录下的图片等资源,而jupyter lab则可能是增强了安全控制,禁止引用本地资源
2.设置密码登录
3.隐藏代码导出html
jupyter nbconvert --to html --template=hidecode.tpl --post serve $1
–post serve 可以通过127.0.0.1:8000访问html文件
–template=hidecode.tpl 隐藏python代码
hidecode.tpl
{% extends 'full.tpl'%}
{% block input_group -%}
{% endblock input_group %}
tpl语法参考Customizing nbconvert
4.嵌入显示matplotlib结果
%matplotlib inline
import matplotlib.pyplot as plt
import numpy
x=numpy.arange(-2,2,0.1)
plt.plot(x,numpy.sin(x))
plt.show()
5.matplotlib显示中文
#matplotlib字体目录:/site-packages/matplotlib/mpl-data/fonts/ttf/
#不支持ttc格式字体文件,譬如放入微软雅黑字体文件msyh.ttf
from matplotlib.font_manager import _rebuild
_rebuild()#重新创建字体索引列表
import matplotlib
matplotlib.rcParams['font.family']=['Microsoft YaHei']
#或者修改/site-packages/matplotlib/mpl-data/matplotlibrc文件中的'font.family'字段
plt.title('中文标题')
plt.plot(x,numpy.sin(x))
plt.show()
JupyterLab使用技巧
本文介绍了JupyterLab的启动配置方法,包括通过指定IP地址实现远程访问、设置密码提高安全性,以及如何隐藏代码导出HTML文件等内容。此外还涵盖了如何在Jupyter环境中配置Matplotlib以支持中文显示和内联展示图表。
4366

被折叠的 条评论
为什么被折叠?



