iPython Notebook,静态交互;我想念什么? [英] iPython Notebook, Static Interact; What am I missing?

查看:96
本文介绍了iPython Notebook,静态交互;我想念什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我在Interactive上发现了这篇文章小部件.

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

然后导入相关软件包:

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

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

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?

最好, 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]))

这篇关于iPython Notebook,静态交互;我想念什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆