|
1 | | -""" anyplot.ai |
| 1 | +"""anyplot.ai |
2 | 2 | ecdf-basic: Basic ECDF Plot |
3 | 3 | Library: bokeh 3.9.1 | Python 3.13.14 |
4 | 4 | Quality: 89/100 | Updated: 2026-06-25 |
|
16 | 16 |
|
17 | 17 | import numpy as np |
18 | 18 | from bokeh.io import output_file, save |
19 | | -from bokeh.models import BoxAnnotation, ColumnDataSource, CrosshairTool, HoverTool, Label, Span |
| 19 | +from bokeh.models import BoxAnnotation, ColumnDataSource, CrosshairTool, CustomJSHover, HoverTool, Label, Span |
20 | 20 | from bokeh.plotting import figure |
21 | 21 | from PIL import Image |
22 | 22 | from selenium import webdriver |
|
93 | 93 | x=q_val, |
94 | 94 | y=y_pos, |
95 | 95 | text=f"{q_lbl}: {q_val:.0f} min", |
96 | | - text_font_size="26pt", |
97 | | - text_color=INK_SOFT, |
| 96 | + text_font_size="30pt", |
| 97 | + text_color=INK, |
98 | 98 | text_font_style="italic", |
99 | 99 | x_offset=14, |
| 100 | + background_fill_color=ELEVATED_BG, |
| 101 | + background_fill_alpha=0.88, |
| 102 | + border_line_color=INK_SOFT, |
| 103 | + border_line_alpha=0.35, |
| 104 | + padding=10, |
100 | 105 | ) |
101 | 106 | ) |
102 | 107 |
|
| 108 | +# Custom JS hover formatters — distinctively Bokeh: show runner count alongside percentage |
| 109 | +fmt_time = CustomJSHover(code="return value.toFixed(0) + ' min'") |
| 110 | +fmt_pct = CustomJSHover( |
| 111 | + code=f""" |
| 112 | + const pct = (value * 100).toFixed(1); |
| 113 | + const runners = Math.round(value * {n_runners}); |
| 114 | + return pct + '% — ' + runners + '/{n_runners} runners'; |
| 115 | +""" |
| 116 | +) |
| 117 | + |
103 | 118 | # Interactive tools — Bokeh strengths |
104 | 119 | p.add_tools( |
105 | 120 | HoverTool( |
106 | | - renderers=[step_renderer], tooltips=[("Finish Time", "@x{0.0} min"), ("Cumulative", "@y{0.0%}")], mode="vline" |
| 121 | + renderers=[step_renderer], |
| 122 | + tooltips=[("Finish Time", "@x{custom}"), ("Cumulative", "@y{custom}")], |
| 123 | + formatters={"@x": fmt_time, "@y": fmt_pct}, |
| 124 | + mode="vline", |
107 | 125 | ) |
108 | 126 | ) |
109 | 127 | p.add_tools(CrosshairTool(dimensions="both", line_color=INK_SOFT, line_alpha=0.45)) |
|
0 commit comments