#!/usr/bin/env python3

# Generate bifurcation diagrams for 1-D maps.
# 
# For a range of different mu values, iterate the map for N steps and plot
# the last L points. The assumption is that the last L points reflect the
# asymptotic behavior.
#
# Example: bifdiag(0,0.001,1,1000,100)

import numpy as np
import matplotlib.pyplot as plt

def bifdiag(mu_start, mu_interval, mu_stop, N, L):

    plt.figure()
    x0=0.1       # initial condition

    mu = np.arange(mu_start,mu_stop,mu_interval)
    
    for i in range(0,len(mu)):
        x = x0*np.ones((N))
        for j in range(0,N-1):
            x[j+1] = 4*mu[i]*x[j]*(1-x[j]) # logistic map
    
        mu_plot = mu[i]*np.ones((L))
        plt.scatter(mu_plot, x[len(x)-L:len(x)],color='black',s=0.1);
    
    plt.show()







