Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions plots/lollipop-basic/implementations/python/matplotlib.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
""" pyplots.ai
""" anyplot.ai
lollipop-basic: Basic Lollipop Chart
Library: matplotlib 3.10.8 | Python 3.13.11
Quality: 92/100 | Created: 2025-12-23
Library: matplotlib 3.10.9 | Python 3.14.4
Quality: 88/100 | Updated: 2026-04-26
"""

import os

import matplotlib.pyplot as plt
import numpy as np


# Data: Product sales by category, sorted by value
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"

BRAND_GREEN = "#009E73"

# Data: Product sales by category
categories = [
"Electronics",
"Clothing",
Expand All @@ -23,30 +33,35 @@
]
values = [87, 72, 65, 58, 52, 45, 41, 38, 32, 25]

# Sort by value descending for better readability
# Sort by value descending for clear ranking
sorted_indices = np.argsort(values)[::-1]
categories = [categories[i] for i in sorted_indices]
values = [values[i] for i in sorted_indices]

# Create plot (4800x2700 px)
fig, ax = plt.subplots(figsize=(16, 9))
fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)
ax.set_facecolor(PAGE_BG)

# Plot lollipop chart: stems + markers
x_positions = np.arange(len(categories))
ax.vlines(x_positions, ymin=0, ymax=values, color="#306998", linewidth=2.5)
ax.scatter(x_positions, values, color="#FFD43B", s=300, zorder=3, edgecolors="#306998", linewidths=2)
ax.vlines(x_positions, ymin=0, ymax=values, color=BRAND_GREEN, linewidth=2.5)
ax.scatter(x_positions, values, color=BRAND_GREEN, s=300, zorder=3, edgecolors=PAGE_BG, linewidths=1.5)

# Labels and styling (scaled for 4800x2700)
ax.set_xlabel("Product Category", fontsize=20)
ax.set_ylabel("Sales (thousands)", fontsize=20)
ax.set_title("lollipop-basic · matplotlib · pyplots.ai", fontsize=24)
ax.set_xlabel("Product Category", fontsize=20, color=INK)
ax.set_ylabel("Sales (thousands)", fontsize=20, color=INK)
ax.set_title("lollipop-basic · matplotlib · anyplot.ai", fontsize=24, fontweight="medium", color=INK)

ax.set_xticks(x_positions)
ax.set_xticklabels(categories, rotation=45, ha="right", fontsize=16)
ax.tick_params(axis="y", labelsize=16)
ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT, labelcolor=INK_SOFT)

ax.set_ylim(0, max(values) * 1.1)
ax.grid(True, alpha=0.3, linestyle="--", axis="y")

ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
for s in ("left", "bottom"):
ax.spines[s].set_color(INK_SOFT)

ax.yaxis.grid(True, alpha=0.15, color=INK, linewidth=0.8)
ax.set_axisbelow(True)

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