1 minute read

</link>

</link>


Been playing around with some of the math functions in Python. I think it’s really cool how such a simple formula can create something so complicated. If you’re interested, I’ve documented the code I used to make the video (apologies for the lack of syntax highlighting at the moment):


import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation

Set up the figure, the axis, and the plot element

fig = plt.figure()
ax = plt.axes(xlim=(0, 60), ylim=(0, 1))
line, = ax.plot([], [], lw=1)

initialization function: plot the background of each frame

def init():
    line.set_data([], [])
    return line,

animation function. This is called sequentially

def animate(r):
    n = np.arange(0,60,1)
    x_n = .5 #initial value for x
    x_list = [] #initiate list

    for i in n:
        if i == 0:
            x_list.append(x_n) #initial value for x
        else:
            x_n1 = rx_n(1-x_n) #logisitic equation (the magic)
            x_list.append(x_n1) #add to x
            x_n = x_n1 #new x becomes old x
    x = np.array(x_list) #turn list into numpy array
    line.set_data(n, x)
    return line,

specify array of parameter values

r = np.arange(2,4.5,.01)

animate, save, show plot

anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=r, interval=60, blit=True)
#anim.save(‘log_map2.mp4’) #use default ffmpeg
plt.show()