Logistic-Map-1

Sat 17 May 2025

from bokeh.plotting import figure, output_file, show
from bokeh.io import output_notebook
from bokeh.models import ColumnDataSource
# Set Bokeh output to notebook
output_notebook()
Loading BokehJS ...
import numpy as np
from bokeh.plotting import figure, show

# Logistic map parameter
r = 3.7  # Control parameter (chaotic behavior for r > 3.57)

# Number of iterations and initial condition
num_points = 10000
x0 = 0.5  # Initial condition

# Generate points for the Logistic map
x = [x0]
for _ in range(num_points - 1):
    x_new = r * x[-1] * (1 - x[-1])
    x.append(x_new)

# Create corresponding y values for visualization
y = np.arange(len(x))

# Split data into segments for multi-line
num_segments = 7
xs = np.array_split(x, num_segments)
ys = np.array_split(y, num_segments)

# Define a color palette
colors = ["#F7FCF0", "#E0F3DB", "#CCEBC5", "#A8DDB5", "#7BCCC4", "#43A2CA", "#0868AC"]

# Create the Bokeh figure
p = figure(title="Logistic Map Visualization",
           background_fill_color="#f9f9f9",
           x_axis_label="Iteration",
           y_axis_label="Value",
           match_aspect=True)

# Add the multi_line glyph
p.multi_line(xs=ys, ys=xs, line_color=colors, line_alpha=0.8, line_width=1.5)

# Show the plot
show(p)


Score: 5

Category: bokeh