Skip to content

Commit 674ec2b

Browse files
feat(seaborn): implement lollipop-basic (#5442)
## Implementation: `lollipop-basic` - python/seaborn Implements the **python/seaborn** version of `lollipop-basic`. **File:** `plots/lollipop-basic/implementations/python/seaborn.py` **Parent Issue:** #934 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/24956781593)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent ed44e30 commit 674ec2b

2 files changed

Lines changed: 212 additions & 142 deletions

File tree

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
lollipop-basic: Basic Lollipop Chart
3-
Library: seaborn 0.13.2 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-23
3+
Library: seaborn 0.13.2 | Python 3.14.4
4+
Quality: 87/100 | Updated: 2026-04-26
55
"""
66

7+
import os
8+
79
import matplotlib.pyplot as plt
810
import pandas as pd
911
import seaborn as sns
1012

1113

12-
# Data - Product sales by category, sorted by value
14+
# Theme tokens
15+
THEME = os.getenv("ANYPLOT_THEME", "light")
16+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
17+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
18+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
19+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
20+
BRAND = "#009E73" # Okabe-Ito position 1
21+
22+
sns.set_theme(
23+
style="ticks",
24+
rc={
25+
"figure.facecolor": PAGE_BG,
26+
"axes.facecolor": PAGE_BG,
27+
"axes.edgecolor": INK_SOFT,
28+
"axes.labelcolor": INK,
29+
"text.color": INK,
30+
"xtick.color": INK_SOFT,
31+
"ytick.color": INK_SOFT,
32+
"grid.color": INK,
33+
"grid.alpha": 0.10,
34+
"legend.facecolor": ELEVATED_BG,
35+
"legend.edgecolor": INK_SOFT,
36+
},
37+
)
38+
39+
# Data - Product sales by category
1340
categories = [
1441
"Electronics",
1542
"Clothing",
@@ -24,32 +51,35 @@
2451
]
2552
values = [85000, 72000, 58000, 45000, 42000, 38000, 35000, 28000, 25000, 18000]
2653

27-
# Create DataFrame and sort by value (ascending for horizontal lollipop)
28-
df = pd.DataFrame({"category": categories, "value": values})
29-
df = df.sort_values("value", ascending=True)
54+
df = pd.DataFrame({"category": categories, "value": values}).sort_values("value", ascending=True)
3055

3156
# Plot
32-
fig, ax = plt.subplots(figsize=(16, 9))
57+
fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)
58+
ax.set_facecolor(PAGE_BG)
3359

34-
# Draw stems (thin lines from baseline to marker)
35-
ax.hlines(y=df["category"], xmin=0, xmax=df["value"], color="#306998", linewidth=2.5, alpha=0.8)
60+
# Stems: thin lines from baseline to marker
61+
ax.hlines(y=df["category"], xmin=0, xmax=df["value"], color=BRAND, linewidth=2.5, alpha=0.85, zorder=2)
3662

37-
# Draw markers (circular dots at data values) using seaborn
63+
# Markers: circular dots at the data values
3864
sns.scatterplot(
39-
data=df, x="value", y="category", s=400, color="#FFD43B", edgecolor="#306998", linewidth=2, ax=ax, zorder=3
65+
data=df, x="value", y="category", s=450, color=BRAND, edgecolor=PAGE_BG, linewidth=2, ax=ax, zorder=3, legend=False
4066
)
4167

42-
# Styling
43-
ax.set_xlabel("Sales ($)", fontsize=20)
44-
ax.set_ylabel("Product Category", fontsize=20)
45-
ax.set_title("lollipop-basic · seaborn · pyplots.ai", fontsize=24)
46-
ax.tick_params(axis="both", labelsize=16)
47-
ax.set_xlim(0, None)
48-
ax.grid(True, axis="x", alpha=0.3, linestyle="--")
68+
# Style
69+
ax.set_xlabel("Sales ($)", fontsize=20, color=INK)
70+
ax.set_ylabel("Product Category", fontsize=20, color=INK)
71+
ax.set_title("lollipop-basic · seaborn · anyplot.ai", fontsize=24, fontweight="medium", color=INK, pad=18)
72+
ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT)
73+
ax.set_xlim(0, max(values) * 1.08)
74+
75+
ax.xaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)
76+
ax.yaxis.grid(False)
77+
ax.set_axisbelow(True)
4978

50-
# Remove top and right spines for cleaner look
5179
ax.spines["top"].set_visible(False)
5280
ax.spines["right"].set_visible(False)
81+
for s in ("left", "bottom"):
82+
ax.spines[s].set_color(INK_SOFT)
5383

5484
plt.tight_layout()
55-
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
85+
plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG)

0 commit comments

Comments
 (0)