title: Graphing n iterations of a function- Python
body: <p>I'm studying dynamical systems, particularly the logistic family g(x) = cx(1-x), and I need to iterate this function an arbitrary amount of times to understand its behavior. I have no problem iterating the function given a specific point x_0, but again, I'd like to graph the entire function and its iterations, not just a single point. For plotting a single function, I have this code:</p>
  
  <pre><code>import numpy as np
  import scipy as sp
  import matplotlib.pyplot as plt
  
  def logplot(c, n = 10):
      dt = .001
      x = np.arange(0,1.001,dt)
      y = c*x*(1-x)
      plt.plot(x,y)
      plt.axis([0, 1, 0, c*.25 + (1/10)*c*.25])
      plt.show()
  </code></pre>
  
  <p>I suppose I could tackle this by the lengthy/daunting method of explicitly creating a list of the range of each iteration using something like the following:</p>
  
  <pre><code>def log(c,x0):
      return c*x0*(1-x)
  
  def logiter(c,x0,n):
      i = 0
      y = []
      while i &lt;= n:
          val = log(c,x0)
          y.append(val)
          x0 = val
          i += 1
      return y
  </code></pre>
  
  <p>But this seems really cumbersome and I was wondering if there were a better way. Thanks</p>