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
74 changes: 53 additions & 21 deletions plots/span-basic/implementations/python/seaborn.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,82 @@
""" pyplots.ai
""" anyplot.ai
span-basic: Basic Span Plot (Highlighted Region)
Library: seaborn 0.13.2 | Python 3.13.11
Quality: 91/100 | Created: 2025-12-23
Library: seaborn 0.13.2 | Python 3.13.13
Quality: 88/100 | Updated: 2026-04-30
"""

import os

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns


# Data - Monthly sales with recession period and target threshold
# Theme tokens
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 = "#009E73" # Okabe-Ito position 1 — always first series
SPAN_RECESSION = "#D55E00" # Okabe-Ito position 2
SPAN_TARGET = "#0072B2" # Okabe-Ito position 3

sns.set_theme(
style="ticks",
rc={
"figure.facecolor": PAGE_BG,
"axes.facecolor": PAGE_BG,
"axes.edgecolor": INK_SOFT,
"axes.labelcolor": INK,
"text.color": INK,
"xtick.color": INK_SOFT,
"ytick.color": INK_SOFT,
"grid.color": INK,
"grid.alpha": 0.10,
"legend.facecolor": ELEVATED_BG,
"legend.edgecolor": INK_SOFT,
},
)

# Data - Monthly sales revenue with recession period and target threshold
np.random.seed(42)
months = pd.date_range(start="2006-01", periods=60, freq="ME")
base_trend = np.linspace(100, 150, 60)
# Dip during recession period (2008-2009)
recession_effect = np.where((months >= "2008-01") & (months <= "2009-12"), -30 * np.sin(np.linspace(0, np.pi, 60)), 0)
sales = base_trend + recession_effect + np.random.randn(60) * 8

df = pd.DataFrame({"Month": months, "Sales": sales})

# Plot
fig, ax = plt.subplots(figsize=(16, 9))
fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)

# Vertical span - recession period (2008-2009)
# Vertical span recession period (20082009)
ax.axvspan(
pd.Timestamp("2008-01-01"),
pd.Timestamp("2009-12-31"),
alpha=0.25,
color="#306998",
label="Recession Period (2008-2009)",
color=SPAN_RECESSION,
label="Recession (20082009)",
)

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

# Line plot using seaborn
sns.lineplot(data=df, x="Month", y="Sales", ax=ax, linewidth=3, color="#306998")
# Line plot
sns.lineplot(data=df, x="Month", y="Sales", ax=ax, linewidth=3, color=BRAND)

# Styling
ax.set_title("span-basic · seaborn · pyplots.ai", fontsize=24)
ax.set_xlabel("Month", fontsize=20)
ax.set_ylabel("Sales (thousands $)", fontsize=20)
ax.tick_params(axis="both", labelsize=16)
# Style
ax.set_title("span-basic · seaborn · anyplot.ai", fontsize=24, fontweight="medium", color=INK)
ax.set_xlabel("Month", fontsize=20, color=INK)
ax.set_ylabel("Sales (thousands $)", fontsize=20, color=INK)
ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT)
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["left"].set_color(INK_SOFT)
ax.spines["bottom"].set_color(INK_SOFT)
ax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)
ax.legend(fontsize=16, loc="upper left")
ax.grid(True, alpha=0.3, linestyle="--")

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