Van-Der-Pol-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()
import numpy as np
from scipy.integrate import odeint
from bokeh.plotting import figure, show
# Van der Pol oscillator parameter
mu = 2.0 # Controls the nonlinearity and damping
# Van der Pol system function
def van_der_pol(state, t):
x, y = state
x_dot = y
y_dot = mu * (1 - x**2) * y - x
return [x_dot, y_dot]
# Initial conditions and time steps
initial = [2, 0]
t = np.linspace(0, 100, 10000)
# Solve Van der Pol equations
solution = odeint(van_der_pol, initial, t)
x = solution[:, 0]
y = solution[:, 1]
# 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 = ["#FFE5D9", "#FFB3B3", "#FF9999", "#FF6666", "#FF3333", "#CC0000", "#990000"]
# Create the Bokeh figure
p = figure(title="Van der Pol Oscillator Visualization",
background_fill_color="#f9f9f9",
x_axis_label="X",
y_axis_label="Y")
# 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)
from IPython.display import Image, display
# Display the image
display(Image(url="https://snipboard.io/HfrZtc.jpg"))

Score: 5
Category: bokeh