Reputation: 1543
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
Upvotes: 4
Views: 2184
Reputation: 5933
%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]))
Upvotes: 2