|
1 | | -""" anyplot.ai |
| 1 | +"""anyplot.ai |
2 | 2 | lollipop-basic: Basic Lollipop Chart |
3 | 3 | Library: bokeh 3.9.1 | Python 3.13.14 |
4 | 4 | Quality: 88/100 | Updated: 2026-07-01 |
|
18 | 18 | from pathlib import Path |
19 | 19 |
|
20 | 20 | from bokeh.io import output_file, save |
21 | | -from bokeh.models import ColumnDataSource, NumeralTickFormatter, Range1d, Span |
| 21 | +from bokeh.models import ColumnDataSource, Label, NumeralTickFormatter, Range1d, Span |
22 | 22 | from bokeh.plotting import figure |
23 | 23 | from PIL import Image |
24 | 24 | from selenium import webdriver |
|
67 | 67 | height=1800, |
68 | 68 | x_range=categories, |
69 | 69 | y_range=Range1d(0, 108000), |
70 | | - title="lollipop-basic · bokeh · anyplot.ai", |
| 70 | + title="lollipop-basic · python · bokeh · anyplot.ai", |
71 | 71 | x_axis_label="Cloud Service", |
72 | 72 | y_axis_label="Monthly Spend (USD)", |
73 | 73 | toolbar_location=None, |
|
77 | 77 | min_border_right=80, |
78 | 78 | ) |
79 | 79 |
|
80 | | -# Average reference line |
| 80 | +# Average reference line + label |
81 | 81 | p.add_layout(Span(location=avg_spend, dimension="width", line_color=INK_MUTED, line_width=3, line_dash="dashed")) |
| 82 | +p.add_layout( |
| 83 | + Label( |
| 84 | + x=2880, |
| 85 | + y=avg_spend, # screen x from plot-frame left; plot area = 3200-180-80=2940px wide |
| 86 | + x_units="screen", |
| 87 | + text=f"Avg: ${avg_spend / 1000:.1f}K", |
| 88 | + text_font_size="22pt", |
| 89 | + text_color=INK_MUTED, |
| 90 | + text_align="right", |
| 91 | + text_baseline="bottom", |
| 92 | + y_offset=8, |
| 93 | + ) |
| 94 | +) |
82 | 95 |
|
83 | 96 | # Stems |
84 | 97 | p.segment(x0="categories", y0="zeros", x1="categories", y1="values", source=source, line_width=4, color=BRAND) |
|
132 | 145 | # Background and chrome |
133 | 146 | p.background_fill_color = PAGE_BG |
134 | 147 | p.border_fill_color = PAGE_BG |
135 | | -p.outline_line_color = INK_SOFT |
| 148 | +p.outline_line_color = None # L-spine only: x/y axis_line_color handle bottom+left |
136 | 149 |
|
137 | 150 | # Y-axis tick format |
138 | 151 | p.yaxis.formatter = NumeralTickFormatter(format="$0,0") |
|
0 commit comments