Skip to content

Commit 11615ab

Browse files
update(density-basic): bokeh — comprehensive quality review
Comprehensive quality review: HoverTool, NumeralTickFormatter, refined rug and grid.
1 parent 2dd92c8 commit 11615ab

2 files changed

Lines changed: 40 additions & 26 deletions

File tree

plots/density-basic/implementations/bokeh.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
""" pyplots.ai
22
density-basic: Basic Density Plot
3-
Library: bokeh 3.8.1 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-23
3+
Library: bokeh 3.8.2 | Python 3.14
4+
Quality: /100 | Updated: 2026-02-23
55
"""
66

77
import numpy as np
88
from bokeh.io import export_png
9-
from bokeh.models import ColumnDataSource
9+
from bokeh.models import ColumnDataSource, HoverTool, NumeralTickFormatter
1010
from bokeh.plotting import figure
1111

1212

@@ -36,16 +36,16 @@
3636
source = ColumnDataSource(data={"x": x_range, "density": density})
3737

3838
# Rug plot data (individual observations)
39-
rug_y_pos = -0.0004 # Position below x-axis
39+
rug_y_pos = -0.0006
4040
rug_source = ColumnDataSource(
4141
data={
4242
"x": response_times,
4343
"y0": np.full_like(response_times, rug_y_pos),
44-
"y1": np.full_like(response_times, rug_y_pos + 0.0004),
44+
"y1": np.full_like(response_times, rug_y_pos + 0.0008),
4545
}
4646
)
4747

48-
# Create figure (4800 x 2700 px for 16:9 landscape)
48+
# Create figure
4949
p = figure(
5050
width=4800,
5151
height=2700,
@@ -55,36 +55,50 @@
5555
)
5656

5757
# Fill under the curve
58-
p.varea(x="x", y1=0, y2="density", source=source, fill_color="#306998", fill_alpha=0.35)
58+
p.varea(x="x", y1=0, y2="density", source=source, fill_color="#306998", fill_alpha=0.25)
5959

6060
# Density curve
61-
p.line(x="x", y="density", source=source, line_color="#306998", line_width=5, line_alpha=0.95)
61+
density_line = p.line(x="x", y="density", source=source, line_color="#306998", line_width=6, line_alpha=0.9)
62+
63+
# Hover tool showing density values at cursor position
64+
hover = HoverTool(
65+
renderers=[density_line],
66+
tooltips=[("Response Time", "@x{0.0} ms"), ("Density", "@density{0.00000}")],
67+
mode="vline",
68+
line_policy="nearest",
69+
)
70+
p.add_tools(hover)
6271

6372
# Rug plot - vertical segments at bottom
64-
p.segment(x0="x", y0="y0", x1="x", y1="y1", source=rug_source, line_color="#306998", line_width=2, line_alpha=0.5)
73+
p.segment(x0="x", y0="y0", x1="x", y1="y1", source=rug_source, line_color="#306998", line_width=3, line_alpha=0.5)
6574

66-
# Style text sizes for large canvas (scaled up)
75+
# Text sizes for large canvas
6776
p.title.text_font_size = "36pt"
6877
p.xaxis.axis_label_text_font_size = "28pt"
6978
p.yaxis.axis_label_text_font_size = "28pt"
7079
p.xaxis.major_label_text_font_size = "22pt"
7180
p.yaxis.major_label_text_font_size = "22pt"
7281

82+
# Y-axis tick format
83+
p.yaxis.formatter = NumeralTickFormatter(format="0.0000")
84+
7385
# Axis styling
7486
p.xaxis.axis_line_width = 2
7587
p.yaxis.axis_line_width = 2
76-
p.xaxis.major_tick_line_width = 2
77-
p.yaxis.major_tick_line_width = 2
88+
p.xaxis.minor_tick_line_color = None
89+
p.yaxis.minor_tick_line_color = None
90+
p.xaxis.major_tick_line_color = None
91+
p.yaxis.major_tick_line_color = None
7892

79-
# Grid styling
80-
p.xgrid.grid_line_alpha = 0.3
81-
p.ygrid.grid_line_alpha = 0.3
82-
p.xgrid.grid_line_dash = "dashed"
83-
p.ygrid.grid_line_dash = "dashed"
93+
# Grid - y-axis only, subtle
94+
p.xgrid.grid_line_color = None
95+
p.ygrid.grid_line_alpha = 0.15
96+
p.ygrid.grid_line_width = 1
8497

8598
# Background
8699
p.background_fill_color = "#fafafa"
87100
p.border_fill_color = "#ffffff"
101+
p.outline_line_color = None
88102

89103
# Remove toolbar
90104
p.toolbar_location = None

plots/density-basic/metadata/bokeh.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
library: bokeh
22
specification_id: density-basic
33
created: '2025-12-23T10:03:19Z'
4-
updated: '2025-12-23T10:10:15Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-23T22:38:00+00:00'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20457534046
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 3.8.1
8+
python_version: 3.14.3
9+
library_version: 3.8.2
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/density-basic/bokeh/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/density-basic/bokeh/plot_thumb.png
1212
preview_html: https://storage.googleapis.com/pyplots-images/plots/density-basic/bokeh/plot.html
13-
quality_score: 92
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques: []
1717
patterns:
18-
- data-generation
19-
- columndatasource
18+
- data-generation
19+
- columndatasource
2020
dataprep:
21-
- kde
21+
- kde
2222
styling:
23-
- alpha-blending
23+
- alpha-blending
2424
review:
2525
strengths:
2626
- Excellent manual KDE implementation using Silverman's rule for bandwidth selection

0 commit comments

Comments
 (0)