title: Bifurcation diagram in matplotlib
body: <p>I'm trying to acquire the bifurcation diagram for the equation below:</p>
  
  <p><img src="https://chart.googleapis.com/chart?cht=tx&amp;chl=%5Cdot%7Bx%7D%20%3D%20rx%20%2B%20x%5E%7B3%7D%20-%20x%5E%7B5%7D" alt="formula"></p>
  
  <p>(x is a function of t)</p>
  
  <p>as:</p>
  
  <p><a href="https://i.stack.imgur.com/xJIcG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xJIcG.jpg" alt="enter image description here"></a></p>
  
  <p>And here is my snippet:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  def pitch(r, x):
      return r * x + np.power(x,3)- np.power(x,5)
  
  n = 10000
  r = np.linspace(-200, 200, n)
  iterations = 1000
  last = 100
  
  x = 0
  
  for i in range(iterations):
      x = pitch(r,x)
  
  if i &gt;= (iterations - last):
      plt.plot(r,x, ',k', alpha=0.02)
  
  plt.title("Bifurcation diagram")
  
  plt.show()
  </code></pre>
  
  <p>But the generated plot is not what it is supposed to be:</p>
  
  <p><a href="https://i.stack.imgur.com/0RuSr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0RuSr.png" alt="enter image description here"></a></p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Here is my recent attempt:</p>
  
  <pre><code>import numpy as np
  from scipy.integrate import odeint
  import matplotlib.pyplot as plt
  
  def pitch(s,x,r):
      x = s[0]
      dxdt = r * x + np.power(x,3)- np.power(x,5)
      return [dxdt]
  
  t = np.linspace(0,100)
  s0=[-50]
  
  r = np.linspace(-200, 200)
  
  for i in r:
      s = odeint(pitch,s0,t, args=(i,))
      plt.plot(s,i,',k', alpha=0.02)
  
  plt.title("Bifurcation diagram")
  
  plt.show()
  </code></pre>
  
  <p>With this error:</p>
  
  <blockquote>
    <p>raise ValueError("x and y must have same first dimension") ValueError:
    x and y must have same first dimension</p>
  </blockquote>
  
  <p>Could you give me some advice to fix this problem?!</p>