我正在尝试跟进所讨论的问题,但未完全解决,这里: Interactive matplotlib using ipywidgets
我在jupyter笔记本环境中使用Python 2.7,并希望在jupyter中以交互方式修改以下函数。
%matplotlib notebook
from ipywidgets import *
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2 * np.pi)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
line, = ax.plot(x, np.sin(x))
def update(w = 1.0):
line.set_ydata(np.sin(w * x))
fig.canvas.draw()
interact(update);
当滑块显示并且可以修改时,不显示任何图形。
我的误解在哪里?
答案 0 :(得分:3)
在jupyter笔记本中没有启用javascript小部件时会发生这种情况。
激活已安装jupyter笔记本的环境。
运行此命令:
jupyter nbextension enable --py --sys-prefix widgetsnbextension
启用笔记本扩展程序jupyter-js-widgets / extension ... - 验证:确定