Skip to content

Commit a70ea3f

Browse files
feat(bokeh): implement line-styled (#2636)
## Implementation: `line-styled` - bokeh Implements the **bokeh** version of `line-styled`. **File:** `plots/line-styled/implementations/bokeh.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20594557446)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent e941886 commit a70ea3f

2 files changed

Lines changed: 143 additions & 0 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
""" pyplots.ai
2+
line-styled: Styled Line Plot
3+
Library: bokeh 3.8.1 | Python 3.13.11
4+
Quality: 92/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, Legend
10+
from bokeh.plotting import figure
11+
12+
13+
# Data - Monthly performance metrics over a year
14+
np.random.seed(42)
15+
months = np.arange(1, 13)
16+
17+
# Generate realistic trending data for different metrics
18+
base = np.array([65, 68, 72, 75, 78, 82, 85, 84, 80, 77, 74, 70])
19+
cpu_usage = base + np.random.randn(12) * 3
20+
memory_usage = base * 0.85 + np.random.randn(12) * 4 + 10
21+
disk_io = base * 0.7 + np.random.randn(12) * 5 + 20
22+
network = base * 1.1 + np.random.randn(12) * 2 - 5
23+
24+
# Create ColumnDataSource
25+
source = ColumnDataSource(
26+
data={"month": months, "cpu": cpu_usage, "memory": memory_usage, "disk": disk_io, "network": network}
27+
)
28+
29+
# Create figure (4800 × 2700 px)
30+
p = figure(
31+
width=4800,
32+
height=2700,
33+
title="line-styled · bokeh · pyplots.ai",
34+
x_axis_label="Month",
35+
y_axis_label="Utilization (%)",
36+
)
37+
38+
# Define line styles and colors
39+
# Using solid, dashed, dotted, and dash-dot patterns with pronounced differences
40+
line_styles = ["solid", [20, 10], [4, 8], [20, 8, 4, 8]]
41+
colors = ["#306998", "#FFD43B", "#4CAF50", "#FF5722"]
42+
series_names = ["CPU Usage", "Memory Usage", "Disk I/O", "Network Traffic"]
43+
y_columns = ["cpu", "memory", "disk", "network"]
44+
45+
# Create legend items
46+
legend_items = []
47+
48+
for col, style, color, name in zip(y_columns, line_styles, colors, series_names, strict=True):
49+
# Add line with appropriate style
50+
line = p.line(x="month", y=col, source=source, line_width=6, color=color, line_dash=style)
51+
52+
# Add scatter points for better visibility
53+
scatter = p.scatter(x="month", y=col, source=source, size=25, color=color, alpha=0.9)
54+
55+
legend_items.append((name, [line, scatter]))
56+
57+
# Create and configure legend - place inside plot area
58+
legend = Legend(items=legend_items, location="top_left")
59+
legend.label_text_font_size = "28pt"
60+
legend.glyph_height = 40
61+
legend.glyph_width = 80
62+
legend.spacing = 15
63+
legend.padding = 20
64+
legend.background_fill_alpha = 0.85
65+
legend.background_fill_color = "white"
66+
legend.border_line_color = "#cccccc"
67+
legend.border_line_width = 2
68+
p.add_layout(legend, "center")
69+
p.legend.location = "top_left"
70+
71+
# Style configuration - larger fonts for 4800x2700 canvas
72+
p.title.text_font_size = "48pt"
73+
p.title.align = "center"
74+
p.xaxis.axis_label_text_font_size = "36pt"
75+
p.yaxis.axis_label_text_font_size = "36pt"
76+
p.xaxis.major_label_text_font_size = "28pt"
77+
p.yaxis.major_label_text_font_size = "28pt"
78+
79+
# Grid styling - subtle
80+
p.grid.grid_line_alpha = 0.3
81+
p.grid.grid_line_dash = "dashed"
82+
83+
# Axis styling
84+
p.xaxis.ticker = list(range(1, 13))
85+
p.xaxis.major_label_overrides = {
86+
1: "Jan",
87+
2: "Feb",
88+
3: "Mar",
89+
4: "Apr",
90+
5: "May",
91+
6: "Jun",
92+
7: "Jul",
93+
8: "Aug",
94+
9: "Sep",
95+
10: "Oct",
96+
11: "Nov",
97+
12: "Dec",
98+
}
99+
100+
# Background and outline
101+
p.background_fill_color = "#fafafa"
102+
p.border_fill_color = "#ffffff"
103+
p.outline_line_color = "#333333"
104+
105+
# Axis line styling
106+
p.xaxis.axis_line_width = 2
107+
p.yaxis.axis_line_width = 2
108+
p.xaxis.major_tick_line_width = 2
109+
p.yaxis.major_tick_line_width = 2
110+
111+
# Save as PNG
112+
export_png(p, filename="plot.png")
113+
114+
# Save as HTML for interactivity
115+
output_file("plot.html")
116+
save(p)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
library: bokeh
2+
specification_id: line-styled
3+
created: '2025-12-30T10:40:59Z'
4+
updated: '2025-12-30T10:50:35Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20594557446
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-styled/bokeh/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/line-styled/bokeh/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/line-styled/bokeh/plot.html
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent text sizing for the 4800×2700 canvas with 48pt title and 36pt axis labels
17+
- All four line styles (solid, dashed, dotted, dash-dot) are clearly distinguishable
18+
as required by spec
19+
- Clean code structure with well-organized ColumnDataSource
20+
- Good use of markers on data points to enhance visibility
21+
- Legend is well-formatted with appropriate sizing and semi-transparent background
22+
weaknesses:
23+
- Grid uses dashed style which can visually compete with the dashed line series
24+
- consider solid grid with lower alpha
25+
- Could add HoverTool for interactivity to better leverage Bokeh's strengths
26+
- Data scenario is somewhat generic - Monthly performance metrics could be more
27+
specific

0 commit comments

Comments
 (0)