I also faced the same problem. They are tracing lines inside my bidurcation diagram. I found this solution.
Here is my code.
import matplotlib.pyplot as plt
import numpy as np
def logistic(x, a):
return a * x * (1 - x)
# Range of 'a' values
k = np.linspace(2.8, 4, 1000)
# Number of iterations and data collection after transients
n = 200
m = 50 # Collect the last 50 points to visualize bifurcation
x_axis = []
y_axis = []
for a in k:
x0 = 0.1 # Initial value of x
# Iterate to remove transient behavior
for i in range(n):
x0 = logistic(x0, a)
# Collect data for plotting bifurcation
for i in range(m):
x0 = logistic(x0, a)
x_axis.append(a)
y_axis.append(x0)
# Plotting the bifurcation diagram
plt.figure(figsize=(10, 7))
plt.plot(x_axis, y_axis, ',k', alpha=0.25) # Small markers for clarity
plt.title("Bifurcation Diagram")
plt.xlabel("Parameter a")
plt.ylabel("Population")
plt.show()
But the problem here why is it loop until 100 at the first loop and then continue the iteration?