|
1 | 1 | """ pyplots.ai |
2 | 2 | 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 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import numpy as np |
8 | 8 | from bokeh.io import export_png |
9 | | -from bokeh.models import ColumnDataSource |
| 9 | +from bokeh.models import ColumnDataSource, HoverTool, NumeralTickFormatter |
10 | 10 | from bokeh.plotting import figure |
11 | 11 |
|
12 | 12 |
|
|
36 | 36 | source = ColumnDataSource(data={"x": x_range, "density": density}) |
37 | 37 |
|
38 | 38 | # Rug plot data (individual observations) |
39 | | -rug_y_pos = -0.0004 # Position below x-axis |
| 39 | +rug_y_pos = -0.0006 |
40 | 40 | rug_source = ColumnDataSource( |
41 | 41 | data={ |
42 | 42 | "x": response_times, |
43 | 43 | "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), |
45 | 45 | } |
46 | 46 | ) |
47 | 47 |
|
48 | | -# Create figure (4800 x 2700 px for 16:9 landscape) |
| 48 | +# Create figure |
49 | 49 | p = figure( |
50 | 50 | width=4800, |
51 | 51 | height=2700, |
|
55 | 55 | ) |
56 | 56 |
|
57 | 57 | # 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) |
59 | 59 |
|
60 | 60 | # 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) |
62 | 71 |
|
63 | 72 | # 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) |
65 | 74 |
|
66 | | -# Style text sizes for large canvas (scaled up) |
| 75 | +# Text sizes for large canvas |
67 | 76 | p.title.text_font_size = "36pt" |
68 | 77 | p.xaxis.axis_label_text_font_size = "28pt" |
69 | 78 | p.yaxis.axis_label_text_font_size = "28pt" |
70 | 79 | p.xaxis.major_label_text_font_size = "22pt" |
71 | 80 | p.yaxis.major_label_text_font_size = "22pt" |
72 | 81 |
|
| 82 | +# Y-axis tick format |
| 83 | +p.yaxis.formatter = NumeralTickFormatter(format="0.0000") |
| 84 | + |
73 | 85 | # Axis styling |
74 | 86 | p.xaxis.axis_line_width = 2 |
75 | 87 | 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 |
78 | 92 |
|
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 |
84 | 97 |
|
85 | 98 | # Background |
86 | 99 | p.background_fill_color = "#fafafa" |
87 | 100 | p.border_fill_color = "#ffffff" |
| 101 | +p.outline_line_color = None |
88 | 102 |
|
89 | 103 | # Remove toolbar |
90 | 104 | p.toolbar_location = None |
|
0 commit comments