|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | lollipop-basic: Basic Lollipop Chart |
3 | | -Library: matplotlib 3.10.8 | Python 3.13.11 |
4 | | -Quality: 92/100 | Created: 2025-12-23 |
| 3 | +Library: matplotlib 3.10.9 | Python 3.14.4 |
| 4 | +Quality: 88/100 | Updated: 2026-04-26 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import matplotlib.pyplot as plt |
8 | 10 | import numpy as np |
9 | 11 |
|
10 | 12 |
|
11 | | -# Data: Product sales by category, sorted by value |
| 13 | +THEME = os.getenv("ANYPLOT_THEME", "light") |
| 14 | +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" |
| 15 | +ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420" |
| 16 | +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" |
| 17 | +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" |
| 18 | + |
| 19 | +BRAND_GREEN = "#009E73" |
| 20 | + |
| 21 | +# Data: Product sales by category |
12 | 22 | categories = [ |
13 | 23 | "Electronics", |
14 | 24 | "Clothing", |
|
23 | 33 | ] |
24 | 34 | values = [87, 72, 65, 58, 52, 45, 41, 38, 32, 25] |
25 | 35 |
|
26 | | -# Sort by value descending for better readability |
| 36 | +# Sort by value descending for clear ranking |
27 | 37 | sorted_indices = np.argsort(values)[::-1] |
28 | 38 | categories = [categories[i] for i in sorted_indices] |
29 | 39 | values = [values[i] for i in sorted_indices] |
30 | 40 |
|
31 | | -# Create plot (4800x2700 px) |
32 | | -fig, ax = plt.subplots(figsize=(16, 9)) |
| 41 | +fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG) |
| 42 | +ax.set_facecolor(PAGE_BG) |
33 | 43 |
|
34 | | -# Plot lollipop chart: stems + markers |
35 | 44 | x_positions = np.arange(len(categories)) |
36 | | -ax.vlines(x_positions, ymin=0, ymax=values, color="#306998", linewidth=2.5) |
37 | | -ax.scatter(x_positions, values, color="#FFD43B", s=300, zorder=3, edgecolors="#306998", linewidths=2) |
| 45 | +ax.vlines(x_positions, ymin=0, ymax=values, color=BRAND_GREEN, linewidth=2.5) |
| 46 | +ax.scatter(x_positions, values, color=BRAND_GREEN, s=300, zorder=3, edgecolors=PAGE_BG, linewidths=1.5) |
38 | 47 |
|
39 | | -# Labels and styling (scaled for 4800x2700) |
40 | | -ax.set_xlabel("Product Category", fontsize=20) |
41 | | -ax.set_ylabel("Sales (thousands)", fontsize=20) |
42 | | -ax.set_title("lollipop-basic · matplotlib · pyplots.ai", fontsize=24) |
| 48 | +ax.set_xlabel("Product Category", fontsize=20, color=INK) |
| 49 | +ax.set_ylabel("Sales (thousands)", fontsize=20, color=INK) |
| 50 | +ax.set_title("lollipop-basic · matplotlib · anyplot.ai", fontsize=24, fontweight="medium", color=INK) |
43 | 51 |
|
44 | 52 | ax.set_xticks(x_positions) |
45 | 53 | ax.set_xticklabels(categories, rotation=45, ha="right", fontsize=16) |
46 | | -ax.tick_params(axis="y", labelsize=16) |
| 54 | +ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT, labelcolor=INK_SOFT) |
47 | 55 |
|
48 | 56 | ax.set_ylim(0, max(values) * 1.1) |
49 | | -ax.grid(True, alpha=0.3, linestyle="--", axis="y") |
| 57 | + |
| 58 | +ax.spines["top"].set_visible(False) |
| 59 | +ax.spines["right"].set_visible(False) |
| 60 | +for s in ("left", "bottom"): |
| 61 | + ax.spines[s].set_color(INK_SOFT) |
| 62 | + |
| 63 | +ax.yaxis.grid(True, alpha=0.15, color=INK, linewidth=0.8) |
| 64 | +ax.set_axisbelow(True) |
50 | 65 |
|
51 | 66 | plt.tight_layout() |
52 | | -plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
| 67 | +plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG) |
0 commit comments