|
1 | | -""" pyplots.ai |
| 1 | +""" anyplot.ai |
2 | 2 | stem-basic: Basic Stem Plot |
3 | | -Library: seaborn 0.13.2 | Python 3.13.11 |
4 | | -Quality: 91/100 | Created: 2025-12-23 |
| 3 | +Library: seaborn 0.13.2 | Python 3.13.13 |
| 4 | +Quality: 88/100 | Updated: 2026-04-30 |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
| 8 | + |
7 | 9 | import matplotlib.pyplot as plt |
8 | 10 | import numpy as np |
9 | 11 | import pandas as pd |
10 | 12 | import seaborn as sns |
11 | 13 |
|
12 | 14 |
|
| 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 | + |
| 21 | +BRAND = "#009E73" |
| 22 | + |
| 23 | +sns.set_theme( |
| 24 | + style="ticks", |
| 25 | + rc={ |
| 26 | + "figure.facecolor": PAGE_BG, |
| 27 | + "axes.facecolor": PAGE_BG, |
| 28 | + "axes.edgecolor": INK_SOFT, |
| 29 | + "axes.labelcolor": INK, |
| 30 | + "text.color": INK, |
| 31 | + "xtick.color": INK_SOFT, |
| 32 | + "ytick.color": INK_SOFT, |
| 33 | + "grid.color": INK, |
| 34 | + "grid.alpha": 0.10, |
| 35 | + "legend.facecolor": ELEVATED_BG, |
| 36 | + "legend.edgecolor": INK_SOFT, |
| 37 | + }, |
| 38 | +) |
| 39 | + |
13 | 40 | # Data - Discrete signal samples (damped sinusoidal impulse response) |
14 | 41 | np.random.seed(42) |
15 | 42 | n_samples = 30 |
16 | 43 | x = np.arange(n_samples) |
17 | 44 | y = np.exp(-0.1 * x) * np.sin(0.5 * x) * 2.5 |
18 | 45 |
|
19 | | -# Create DataFrame for seaborn |
20 | 46 | df = pd.DataFrame({"Sample Index": x, "Amplitude": y}) |
21 | 47 |
|
22 | | -# Plot |
23 | 48 | fig, ax = plt.subplots(figsize=(16, 9)) |
24 | 49 |
|
25 | 50 | # Draw stems (thin vertical lines from baseline y=0 to data values) |
26 | | -ax.vlines(x=df["Sample Index"], ymin=0, ymax=df["Amplitude"], color="#306998", linewidth=2.5, alpha=0.8) |
| 51 | +ax.vlines(x=df["Sample Index"], ymin=0, ymax=df["Amplitude"], color=BRAND, linewidth=2.5, alpha=0.8) |
27 | 52 |
|
28 | 53 | # Draw markers at top of stems using seaborn |
29 | 54 | sns.scatterplot( |
30 | | - data=df, x="Sample Index", y="Amplitude", s=300, color="#FFD43B", edgecolor="#306998", linewidth=2, ax=ax, zorder=3 |
| 55 | + data=df, x="Sample Index", y="Amplitude", s=300, color=BRAND, edgecolor=PAGE_BG, linewidth=2, ax=ax, zorder=3 |
31 | 56 | ) |
32 | 57 |
|
33 | 58 | # Draw baseline at y=0 |
34 | | -ax.axhline(y=0, color="#306998", linewidth=1.5, alpha=0.5) |
| 59 | +ax.axhline(y=0, color=INK_SOFT, linewidth=1.5, alpha=0.5) |
35 | 60 |
|
36 | | -# Styling |
37 | 61 | ax.set_xlabel("Sample Index (n)", fontsize=20) |
38 | 62 | ax.set_ylabel("Amplitude", fontsize=20) |
39 | | -ax.set_title("stem-basic · seaborn · pyplots.ai", fontsize=24) |
| 63 | +ax.set_title("stem-basic · seaborn · anyplot.ai", fontsize=24) |
40 | 64 | ax.tick_params(axis="both", labelsize=16) |
41 | | -ax.grid(True, alpha=0.3, linestyle="--") |
42 | 65 |
|
43 | | -# Remove top and right spines for cleaner look |
| 66 | +ax.yaxis.grid(True, linestyle="-", linewidth=0.8, alpha=0.15) |
| 67 | +ax.set_axisbelow(True) |
| 68 | + |
44 | 69 | ax.spines["top"].set_visible(False) |
45 | 70 | ax.spines["right"].set_visible(False) |
46 | 71 |
|
47 | 72 | plt.tight_layout() |
48 | | -plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
| 73 | +plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG) |
0 commit comments