Rossler-Attractor

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

# Rossler system parameters
a = 0.2
b = 0.2
c = 5.7

# Rossler system function
def rossler(state, t):
    x, y, z = state
    x_dot = -y - z
    y_dot = x + a * y
    z_dot = b + z * (x - c)
    return [x_dot, y_dot, z_dot]

# Initial conditions and time steps
initial = [0, 1, 0]
t = np.linspace(0, 100, 10000)

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

# Rotate the data for a different perspective
theta = np.pi / 4
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 = ["#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043", "#67001F", "#3B0D0A"]

# Create the Bokeh figure
p = figure(title="Rossler 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