机器学习三剑客补充

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()

猜你喜欢

转载自www.cnblogs.com/xiaoxiaoxl/p/11110011.html