Skip to content

Commit d63fcd0

Browse files
feat(plotnine): implement lollipop-basic (#9599)
## Implementation: `lollipop-basic` - python/plotnine Implements the **python/plotnine** version of `lollipop-basic`. **File:** `plots/lollipop-basic/implementations/python/plotnine.py` **Parent Issue:** #934 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/28496693186)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent 40a72d9 commit d63fcd0

2 files changed

Lines changed: 139 additions & 81 deletions

File tree

plots/lollipop-basic/implementations/python/plotnine.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
""" anyplot.ai
22
lollipop-basic: Basic Lollipop Chart
3-
Library: plotnine 0.15.3 | Python 3.14.4
4-
Quality: 85/100 | Updated: 2026-04-26
3+
Library: plotnine 0.15.7 | Python 3.13.14
4+
Quality: 84/100 | Updated: 2026-07-01
55
"""
66

77
import os
8+
import sys
9+
10+
11+
# Prevent circular import: remove this script's directory from sys.path so
12+
# "from plotnine import ..." resolves to the installed library, not this file.
13+
_here = os.path.dirname(os.path.abspath(__file__))
14+
sys.path = [p for p in sys.path if os.path.abspath(p) != _here]
815

916
import pandas as pd
1017
from plotnine import (
1118
aes,
19+
element_blank,
1220
element_line,
1321
element_rect,
1422
element_text,
1523
geom_point,
1624
geom_segment,
25+
geom_text,
1726
ggplot,
1827
ggsave,
1928
labs,
29+
scale_size_continuous,
2030
theme,
2131
theme_minimal,
2232
)
@@ -28,7 +38,7 @@
2838
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
2939
BRAND = "#009E73"
3040

31-
# Data - Product sales by category, sorted by value
41+
# Product sales by category, sorted ascending for ranking narrative
3242
data = {
3343
"category": [
3444
"Electronics",
@@ -48,28 +58,37 @@
4858
df = pd.DataFrame(data)
4959
df = df.sort_values("value", ascending=True).reset_index(drop=True)
5060
df["category"] = pd.Categorical(df["category"], categories=df["category"], ordered=True)
61+
df["label"] = df["value"].astype(str) + "k"
5162

52-
# Plot
5363
plot = (
5464
ggplot(df, aes(x="category", y="value"))
55-
+ geom_segment(aes(x="category", xend="category", y=0, yend="value"), color=BRAND, size=1.5)
56-
+ geom_point(color=BRAND, size=6, fill=BRAND)
57-
+ labs(x="Product Category", y="Sales (thousands $)", title="lollipop-basic · plotnine · anyplot.ai")
65+
+ geom_segment(aes(x="category", xend="category", y=0, yend="value"), color=BRAND, size=0.6)
66+
+ geom_point(aes(size="value"), color=BRAND, fill=BRAND, show_legend=False)
67+
+ geom_text(
68+
aes(label="label"),
69+
color=INK_SOFT,
70+
size=2.8, # geom_text size is in mm (~2.8mm ≈ 8pt at dpi=400)
71+
nudge_y=16,
72+
va="bottom",
73+
)
74+
+ scale_size_continuous(range=[2, 7])
75+
+ labs(x="Product Category", y="Sales (thousands $)", title="lollipop-basic · python · plotnine · anyplot.ai")
5876
+ theme_minimal()
5977
+ theme(
60-
figure_size=(16, 9),
78+
figure_size=(8, 4.5),
6179
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
6280
panel_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
63-
text=element_text(size=14, color=INK),
64-
axis_title=element_text(size=20, color=INK),
65-
axis_text=element_text(size=16, color=INK_SOFT),
81+
panel_border=element_blank(),
82+
text=element_text(size=7, color=INK),
83+
axis_title=element_text(size=10, color=INK),
84+
axis_text=element_text(size=8, color=INK_SOFT),
6685
axis_text_x=element_text(angle=45, ha="right", color=INK_SOFT),
6786
axis_line=element_line(color=INK_SOFT),
68-
plot_title=element_text(size=24, color=INK),
69-
panel_grid_minor=element_line(alpha=0),
70-
panel_grid_major_x=element_line(alpha=0),
87+
plot_title=element_text(size=12, color=INK),
88+
panel_grid_minor=element_blank(),
89+
panel_grid_major_x=element_blank(),
7190
panel_grid_major_y=element_line(color=INK, alpha=0.15, size=0.3),
7291
)
7392
)
7493

75-
ggsave(plot, filename=f"plot-{THEME}.png", dpi=300, width=16, height=9)
94+
ggsave(plot, filename=f"plot-{THEME}.png", dpi=400, width=8, height=4.5, units="in")

0 commit comments

Comments
 (0)