iPython Notebook, Static Interact; What am I missing?

筅森魡賤 提交于 2019-12-07 18:23:34

问题


Recently I found this post on Interactive Widgets.

I am trying to implement this in some simple code, which iterates the logistic equation, and plots the consequent timeseries:

%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

Then import the relevant packages:

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]))

But, Alas, the output is a mess. It seems to be plotting all possible combinations of r,t and x0 instead of just one.

Can anyone tell me what I'm doing wrong?

best, T


回答1:


%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]))


来源:https://stackoverflow.com/questions/29098281/ipython-notebook-static-interact-what-am-i-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!