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. 设置密码登录
Running a notebook server
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()
来源: http://www.bubuko.com/infodetail-3109026.html