Skip to content

Commit 6f051e8

Browse files
feat(seaborn): implement span-basic (#5611)
## Implementation: `span-basic` - python/seaborn Implements the **python/seaborn** version of `span-basic`. **File:** `plots/span-basic/implementations/python/seaborn.py` **Parent Issue:** #980 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25160803525)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Markus Neusinger <2921697+MarkusNeusinger@users.noreply.github.com>
1 parent 50dd5a3 commit 6f051e8

2 files changed

Lines changed: 213 additions & 140 deletions

File tree

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,82 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
span-basic: Basic Span Plot (Highlighted Region)
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
55
"""
66

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

1214

13-
# Data - Monthly sales with recession period and target threshold
15+
# Theme tokens
16+
THEME = os.getenv("ANYPLOT_THEME", "light")
17+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
18+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
19+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
20+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
21+
22+
BRAND = "#009E73" # Okabe-Ito position 1 — always first series
23+
SPAN_RECESSION = "#D55E00" # Okabe-Ito position 2
24+
SPAN_TARGET = "#0072B2" # Okabe-Ito position 3
25+
26+
sns.set_theme(
27+
style="ticks",
28+
rc={
29+
"figure.facecolor": PAGE_BG,
30+
"axes.facecolor": PAGE_BG,
31+
"axes.edgecolor": INK_SOFT,
32+
"axes.labelcolor": INK,
33+
"text.color": INK,
34+
"xtick.color": INK_SOFT,
35+
"ytick.color": INK_SOFT,
36+
"grid.color": INK,
37+
"grid.alpha": 0.10,
38+
"legend.facecolor": ELEVATED_BG,
39+
"legend.edgecolor": INK_SOFT,
40+
},
41+
)
42+
43+
# Data - Monthly sales revenue with recession period and target threshold
1444
np.random.seed(42)
1545
months = pd.date_range(start="2006-01", periods=60, freq="ME")
1646
base_trend = np.linspace(100, 150, 60)
17-
# Dip during recession period (2008-2009)
1847
recession_effect = np.where((months >= "2008-01") & (months <= "2009-12"), -30 * np.sin(np.linspace(0, np.pi, 60)), 0)
1948
sales = base_trend + recession_effect + np.random.randn(60) * 8
20-
2149
df = pd.DataFrame({"Month": months, "Sales": sales})
2250

2351
# Plot
24-
fig, ax = plt.subplots(figsize=(16, 9))
52+
fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)
2553

26-
# Vertical span - recession period (2008-2009)
54+
# Vertical span recession period (20082009)
2755
ax.axvspan(
2856
pd.Timestamp("2008-01-01"),
2957
pd.Timestamp("2009-12-31"),
3058
alpha=0.25,
31-
color="#306998",
32-
label="Recession Period (2008-2009)",
59+
color=SPAN_RECESSION,
60+
label="Recession (20082009)",
3361
)
3462

35-
# Horizontal span - target sales zone (120-140)
36-
ax.axhspan(120, 140, alpha=0.2, color="#FFD43B", label="Target Zone (120-140)")
63+
# Horizontal span target sales zone (120140)
64+
ax.axhspan(120, 140, alpha=0.20, color=SPAN_TARGET, label="Target Zone (120140)")
3765

38-
# Line plot using seaborn
39-
sns.lineplot(data=df, x="Month", y="Sales", ax=ax, linewidth=3, color="#306998")
66+
# Line plot
67+
sns.lineplot(data=df, x="Month", y="Sales", ax=ax, linewidth=3, color=BRAND)
4068

41-
# Styling
42-
ax.set_title("span-basic · seaborn · pyplots.ai", fontsize=24)
43-
ax.set_xlabel("Month", fontsize=20)
44-
ax.set_ylabel("Sales (thousands $)", fontsize=20)
45-
ax.tick_params(axis="both", labelsize=16)
69+
# Style
70+
ax.set_title("span-basic · seaborn · anyplot.ai", fontsize=24, fontweight="medium", color=INK)
71+
ax.set_xlabel("Month", fontsize=20, color=INK)
72+
ax.set_ylabel("Sales (thousands $)", fontsize=20, color=INK)
73+
ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT)
74+
ax.spines["top"].set_visible(False)
75+
ax.spines["right"].set_visible(False)
76+
ax.spines["left"].set_color(INK_SOFT)
77+
ax.spines["bottom"].set_color(INK_SOFT)
78+
ax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)
4679
ax.legend(fontsize=16, loc="upper left")
47-
ax.grid(True, alpha=0.3, linestyle="--")
4880

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

0 commit comments

Comments
 (0)