iPython 笔记本,静态交互;我错过了什么?

iPython Notebook, Static Interact; What am I missing?

最近我在 Interactive Widgets 上找到 this post

我试图用一些简单的代码来实现它,它迭代逻辑方程,并绘制结果时间序列:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import pylab
from IPython.html.widgets import interact

plt.close('all')

def logiter(r, x0, t):
    y = []
    x = x0
    for i in range(t):
        x = r*x*(1-x)
        y.append(x)

    fig, plt.plot(y)
    return fig

然后导入相关包:

from ipywidgets import StaticInteract, RangeWidget, RadioWidget

StaticInteract(logiter,
               r=RadioWidget([1, 2, 4]),
               t=RangeWidget(1, 10, 1),
               x0=RadioWidget([0.1, 0.3, 0.7]))

但是,唉,输出一团糟。它似乎在绘制 r、t 和 x0 的所有可能组合,而不仅仅是一个。

谁能告诉我我做错了什么?

最佳, T

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
#from IPython.html.widgets import interact

#plt.close('all')

def logiter(r, x0, t):
    y = []
    x = x0
    fig=plt.figure()
    for i in range(t):
        x = r*x*(1-x)
        y.append(x)

    plt.plot(y)
    return fig
from ipywidgets import StaticInteract, RangeWidget, RadioWidget

StaticInteract(logiter,
               r=RadioWidget([1, 2, 4]),
               t=RangeWidget(1, 10, 1),
               x0=RadioWidget([0.1, 0.3, 0.7]))