首页 > 解决方案 > nbviewer 中未显示函数输入的小部件

问题描述

我编写了一个 python 模块,并希望通过 jupyter notebook 提供一些功能。为此,我想可视化(绘制)函数。笔记本应该是交互式的,即用户可以更改输入并获得相应的结果/绘图。

我试图让一个用例工作,因为我以前从未使用过 jupyter。我跟着这个。这是他们网站上的代码:

%matplotlib inline
from ipywidgets import interact
import matplotlib.pyplot as plt
import numpy as np

def f(m, b):
    plt.figure(2)
    x = np.linspace(-10, 10, num=1000)
    plt.plot(x, m * x + b)
    plt.ylim(-5, 5)
    plt.show()

interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot

本地一切正常。一旦我将它上传到 github 并想在 nbviewer 上显示它(可以在此处找到),交互式滑块就不起作用。我究竟做错了什么?

python版本对此有限制吗?

标签: pythonjupyter-notebook

解决方案


推荐阅读