Jupyter
跳转到导航
跳转到搜索
扩展
自动加载模块[1]
%load_ext autoreload
%aimport mod
from mod import xxx
有用的片断
基本
重新加载模块
import sys
if 'lib' in sys.modules:
del sys.modules['lib']
from lib import *
配置
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (20.0, 10.0)
# plt.rcParams['font.family'] = "STXihei"
图例
plt.plot(..., label='X')
plt.plot(..., label='Y')
plt.legend(framealpha=0.5, fontsize=16)
坐标网格
plt.minorticks_on() # 更细致的网格
plt.grid(which='minor', linestyle=':', linewidth='0.5', color='gray')
plt.grid()
坐标格式化
import matplotlib.ticker as ticker
def format_time(x, pos=None):
return humantime(x)
plt.axes().yaxis.set_major_formatter(ticker.FuncFormatter(format_time))
斜的日期横坐标
fig, ax = plt.subplots(1)
fig.autofmt_xdate()
交互式图像
安装 ipympl 包,然后使用 %matplotlib widget 指令。
注意:画图开始前,需要调用一下 plt.figure(),否则会复用到上一个图像上。
配置
键盘快捷键、UI 的设置保存于 ~/.jupyter/nbconfig/notebook.json。