|
1 | | -""" anyplot.ai |
| 1 | +"""anyplot.ai |
2 | 2 | lollipop-basic: Basic Lollipop Chart |
3 | 3 | Library: altair 6.2.2 | Python 3.13.14 |
4 | 4 | Quality: 87/100 | Updated: 2026-07-01 |
|
55 | 55 | alt.Chart(df) |
56 | 56 | .mark_rule(strokeWidth=4) |
57 | 57 | .encode( |
58 | | - x=alt.X("category:N", sort="-y", title="Category", axis=alt.Axis(labelAngle=-35)), |
| 58 | + x=alt.X("category:N", sort="-y", title="Category", axis=alt.Axis(labelAngle=-45, labelFontSize=9)), |
59 | 59 | y=alt.Y("value:Q", title="Sales (USD)", axis=alt.Axis(format="$,.0f")), |
60 | 60 | color=alt.value(BRAND), |
61 | 61 | opacity=alt.condition(selection, alt.value(1.0), alt.value(0.3)), |
|
77 | 77 | ) |
78 | 78 | ) |
79 | 79 |
|
| 80 | +# Value annotation on top performer to anchor the narrative (DE-03) |
| 81 | +annotation_df = df[df["category"] == "Electronics"].copy() |
| 82 | +annotation = ( |
| 83 | + alt.Chart(annotation_df) |
| 84 | + .mark_text(dy=-18, fontSize=10, fontWeight="bold") |
| 85 | + .encode( |
| 86 | + x=alt.X("category:N", sort="-y"), |
| 87 | + y=alt.Y("value:Q"), |
| 88 | + text=alt.Text("value:Q", format="$,.0f"), |
| 89 | + color=alt.value(INK), |
| 90 | + ) |
| 91 | +) |
| 92 | + |
80 | 93 | # Title: n=73 chars → fontsize = round(16 × 67/73) = 15 |
81 | 94 | TITLE = "Product Sales by Category · lollipop-basic · python · altair · anyplot.ai" |
82 | 95 |
|
83 | 96 | chart = ( |
84 | | - (stems + dots) |
| 97 | + (stems + dots + annotation) |
85 | 98 | .properties( |
86 | 99 | width=620, |
87 | 100 | height=320, |
|
91 | 104 | .configure_view(fill=PAGE_BG, stroke=None) |
92 | 105 | .configure_axis( |
93 | 106 | domainColor=INK_SOFT, |
| 107 | + domainOpacity=0, |
94 | 108 | domainWidth=1, |
95 | 109 | tickColor=INK_SOFT, |
96 | 110 | gridColor=INK, |
|
0 commit comments