I am playing with the code in this tutorial of the Barnsley fern, and I would like the fern to be plotted slowly (not at once). Python is not comfortable, yet, and I see that the function plt.pause() may do the trick in some other answers; however, I don't know how to combine plt.pause() with plt.scatter() to obtain an animated gif effect. Would I have to incorporate plt.scatter within the for loop, for example?
# importing necessary modules
import matplotlib.pyplot as plt
from random import randint
# initializing the list
x = []
y = []
# setting first element to 0
x.append(0)
y.append(0)
current = 0
for i in range(1, 50000):
# generates a random integer between 1 and 100
z = randint(1, 100)
# the x and y coordinates of the equations
# are appended in the lists respectively.
# for the probability 0.01
if z == 1:
a = 0; b = 0; c = 0; d = 0.16; e = 0; f = 0
x.append(0)
y.append(d*(y[current]))
# for the probability 0.85
if z>= 2 and z<= 86:
a = 0.85; b = 0.04; c = -0.04; d = 0.85; e = 0; f = 1.6
x.append(a*(x[current]) + b*(y[current]))
y.append(c*(x[current]) + d*(y[current])+f)
# for the probability 0.07
if z>= 87 and z<= 93:
a = 0.2; b = -0.26; c = 0.23; d = 0.22; e = 0; f = 1.6
x.append(a*(x[current]) + b*(y[current]))
y.append(c*(x[current]) + d*(y[current])+f)
# for the probability 0.07
if z>= 94 and z<= 100:
a = -0.15; b = 0.28; c = 0.26; d = 0.24; e = 0; f = 0.44
x.append(a*(x[current]) + b*(y[current]))
y.append(c*(x[current]) + d*(y[current])+f)
current = current + 1
plt.figure(figsize=(10,10))
plt.scatter(x, y, s = 0.2, edgecolor ='green')
This is the desired effect: