Lorenz-Similar-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 scipy.integrate import odeint
from bokeh.plotting import figure, show

# Lorenz system parameters
sigma = 10
rho = 28
beta = 8.0 / 3
theta = 3 * np.pi / 4

# Lorenz system function
def lorenz(xyz, t):
    x, y, z = xyz
    x_dot = sigma * (y - x)
    y_dot = x * rho - x * z - y
    z_dot = x * y - beta * z
    return [x_dot, y_dot, z_dot]

# Initial conditions and time steps
initial = (-10, -7, 35)
t = np.arange(0, 100, 0.006)

# Solve Lorenz equations
solution = odeint(lorenz, initial, t)
x = solution[:, 0]
y = solution[:, 1]
z = solution[:, 2]

# Rotate data for a different perspective
xprime = np.cos(theta) * x - np.sin(theta) * y

# Split data into segments for multi_line
num_segments = 7
xs = np.array_split(xprime, num_segments)
ys = np.array_split(z, num_segments)

# Define a color palette
colors = ["#C6DBEF", "#9ECAE1", "#6BAED6", "#4292C6", "#2171B5", "#08519C", "#08306B"]

# Create the Bokeh figure
p = figure(title="Lorenz Attractor Visualization",
           background_fill_color="#f9f9f9",
           x_axis_label="X'",
           y_axis_label="Z")

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

# Show the plot
show(p)


Score: 5

Category: bokeh