Skip to content

Commit 4fe401e

Browse files
feat(bokeh): implement line-stepwise (#2625)
## Implementation: `line-stepwise` - bokeh Implements the **bokeh** version of `line-stepwise`. **File:** `plots/line-stepwise/implementations/bokeh.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20594558941)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent fcf6d38 commit 4fe401e

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
""" pyplots.ai
2+
line-stepwise: Step Line Plot
3+
Library: bokeh 3.8.1 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
from bokeh.io import export_png, output_file, save
9+
from bokeh.models import ColumnDataSource
10+
from bokeh.plotting import figure
11+
12+
13+
# Data - CPU usage readings over time with discrete state changes
14+
np.random.seed(42)
15+
n_points = 24
16+
hours = np.arange(n_points)
17+
18+
# Create realistic CPU usage that stays at levels then jumps
19+
base_levels = [35, 45, 75, 85, 90, 80, 60, 40, 30, 25, 40, 55, 70, 85, 95, 90, 75, 60, 50, 45, 35, 30, 25, 20]
20+
cpu_usage = np.array(base_levels[:n_points], dtype=float)
21+
22+
# Add small noise to make it realistic
23+
cpu_usage += np.random.uniform(-2, 2, n_points)
24+
cpu_usage = np.clip(cpu_usage, 0, 100)
25+
26+
# Create step function data by duplicating points
27+
# For 'post' step style: value changes after the point
28+
x_step = []
29+
y_step = []
30+
for i in range(len(hours)):
31+
x_step.append(hours[i])
32+
y_step.append(cpu_usage[i])
33+
if i < len(hours) - 1:
34+
x_step.append(hours[i + 1])
35+
y_step.append(cpu_usage[i])
36+
37+
# Create data source
38+
source = ColumnDataSource(data={"x": x_step, "y": y_step})
39+
40+
# Create figure
41+
p = figure(
42+
width=4800,
43+
height=2700,
44+
title="line-stepwise · bokeh · pyplots.ai",
45+
x_axis_label="Hour of Day",
46+
y_axis_label="CPU Usage (%)",
47+
)
48+
49+
# Plot step line
50+
p.line(x="x", y="y", source=source, line_width=4, line_color="#306998", line_alpha=0.9)
51+
52+
# Add markers at actual data points for clarity
53+
marker_source = ColumnDataSource(data={"x": hours, "y": cpu_usage})
54+
55+
p.scatter(x="x", y="y", source=marker_source, size=12, color="#306998", alpha=0.9)
56+
57+
# Style text sizes for large canvas
58+
p.title.text_font_size = "28pt"
59+
p.xaxis.axis_label_text_font_size = "22pt"
60+
p.yaxis.axis_label_text_font_size = "22pt"
61+
p.xaxis.major_label_text_font_size = "18pt"
62+
p.yaxis.major_label_text_font_size = "18pt"
63+
64+
# Grid styling
65+
p.xgrid.grid_line_alpha = 0.3
66+
p.ygrid.grid_line_alpha = 0.3
67+
p.xgrid.grid_line_dash = "dashed"
68+
p.ygrid.grid_line_dash = "dashed"
69+
70+
# Background
71+
p.background_fill_color = "#fafafa"
72+
73+
# Axis ranges
74+
p.y_range.start = 0
75+
p.y_range.end = 105
76+
77+
# Save as PNG and HTML
78+
export_png(p, filename="plot.png")
79+
80+
# Also save as HTML for interactive version
81+
output_file("plot.html")
82+
save(p)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library: bokeh
2+
specification_id: line-stepwise
3+
created: '2025-12-30T10:38:37Z'
4+
updated: '2025-12-30T10:47:59Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20594558941
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 3.8.1
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/line-stepwise/bokeh/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-stepwise/bokeh/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/line-stepwise/bokeh/plot.html
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent step line implementation with manual coordinate transformation for post
17+
step style
18+
- Perfect title format following the spec-id · library · pyplots.ai convention
19+
- Realistic CPU usage scenario that naturally demonstrates stepwise behavior
20+
- Good visual clarity with appropriate font sizes for large canvas
21+
- Proper use of ColumnDataSource for data management
22+
- Clean, readable code following KISS principles
23+
- Both PNG and HTML outputs provided for static and interactive viewing
24+
weaknesses:
25+
- Does not use Bokeh native step line mode (line with step_mode parameter) which
26+
would be more idiomatic
27+
- Missing HoverTool which would enhance the interactive HTML version
28+
- Markers could be slightly larger for better visibility at the target resolution
29+
- Small random noise in data slightly contradicts the discrete state changes concept
30+
from the spec

0 commit comments

Comments
 (0)