python - 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版本对此有限制吗?
解决方案
推荐阅读
- java - 如何用“(”分割java字符串?
- mysql - 如何在mysql表上存储多个值
- c - Mandelbrot 在 OpenGL 中设置 - C
- android - 在 RatingBar 上设置监听器总是被调用
- amazon-web-services - 无法从 Lambda 连接到 AWS documentDb
- php - 列类型为文本时如何获取列的最小值?
- mongodb - 无法理解 bgchaindb 的行为?
- javascript - 添加到 Uint32Array 时 0x100000000 >>> 0 在 Javascript 中实际上做了什么
- java - XMLSignature 默认为 RSA,如何验证 SSL 签名的 DSA 曲线?
- c - 如何使用 DejaGnu 设置单元测试