Skip to content

Commit 1b7ca29

Browse files
Merge branch 'main' into implementation/span-basic/highcharts
2 parents 96da0b5 + b89dbac commit 1b7ca29

6 files changed

Lines changed: 645 additions & 446 deletions

File tree

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
span-basic: Basic Span Plot (Highlighted Region)
3-
Library: bokeh 3.8.1 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-23
3+
Library: bokeh 3.9.0 | Python 3.13.13
4+
Quality: 89/100 | Updated: 2026-04-30
55
"""
66

7+
import os
8+
79
import numpy as np
810
from bokeh.io import export_png, output_file, save
9-
from bokeh.models import BoxAnnotation, ColumnDataSource, Label
11+
from bokeh.models import BoxAnnotation, ColumnDataSource, HoverTool, Label
1012
from bokeh.plotting import figure
1113

1214

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+
BRAND = "#009E73" # Okabe-Ito position 1 — always first series
22+
1323
# Data - Monthly revenue over 2 years with spans highlighting key periods
1424
np.random.seed(42)
1525
months = np.arange(1, 25)
@@ -24,56 +34,79 @@
2434
p = figure(
2535
width=4800,
2636
height=2700,
27-
title="span-basic · bokeh · pyplots.ai",
37+
title="span-basic · bokeh · anyplot.ai",
2838
x_axis_label="Month",
2939
y_axis_label="Revenue (thousands $)",
3040
)
3141

3242
# Add vertical span - highlight Q4 of Year 1 (months 10-12)
3343
vertical_span = BoxAnnotation(
34-
left=10, right=12, fill_alpha=0.25, fill_color="#306998", line_color="#306998", line_width=2, line_alpha=0.5
44+
left=10, right=12, fill_alpha=0.25, fill_color="#0072B2", line_color="#0072B2", line_width=2, line_alpha=0.5
3545
)
3646
p.add_layout(vertical_span)
3747

3848
# Add horizontal span - highlight target revenue range (120-140)
3949
horizontal_span = BoxAnnotation(
40-
bottom=120, top=140, fill_alpha=0.2, fill_color="#FFD43B", line_color="#FFD43B", line_width=2, line_alpha=0.5
50+
bottom=120, top=140, fill_alpha=0.2, fill_color="#E69F00", line_color="#E69F00", line_width=2, line_alpha=0.5
4151
)
4252
p.add_layout(horizontal_span)
4353

44-
# Plot line with markers
45-
p.line(x="x", y="y", source=source, line_width=4, line_color="#306998", legend_label="Monthly Revenue")
46-
p.scatter(x="x", y="y", source=source, size=16, fill_color="#306998", line_color="white", line_width=2)
54+
# Plot line with markers (Okabe-Ito position 1)
55+
p.line(x="x", y="y", source=source, line_width=4, line_color=BRAND, legend_label="Monthly Revenue")
56+
p.scatter(x="x", y="y", source=source, size=20, fill_color=BRAND, line_color=PAGE_BG, line_width=2)
57+
58+
# HoverTool — showcases Bokeh's interactive HTML output
59+
hover = HoverTool(tooltips=[("Month", "@x"), ("Revenue", "@y{0.1} K$")])
60+
p.add_tools(hover)
4761

48-
# Add labels for spans
62+
# Add labels for spans — positioned prominently at top of each span
4963
vertical_label = Label(
50-
x=10.2, y=102, text="Q4 Peak Season", text_font_size="24pt", text_color="#1a4d7c", text_font_style="bold"
64+
x=10.2, y=143, text="Q4 Peak Season", text_font_size="28pt", text_color="#0072B2", text_font_style="bold"
5165
)
5266
p.add_layout(vertical_label)
5367

5468
horizontal_label = Label(
55-
x=17, y=125, text="Target Range", text_font_size="28pt", text_color="#B8860B", text_font_style="bold"
69+
x=17,
70+
y=124,
71+
text="Target Range",
72+
text_font_size="28pt",
73+
text_color="#B8720B" if THEME == "light" else "#E69F00",
74+
text_font_style="bold",
5675
)
5776
p.add_layout(horizontal_label)
5877

59-
# Style text sizes for 4800x2700 px
78+
# Apply theme-adaptive chrome
79+
p.background_fill_color = PAGE_BG
80+
p.border_fill_color = PAGE_BG
81+
p.outline_line_color = None # remove box border; L-shaped spines via xaxis/yaxis lines only
82+
83+
p.title.text_color = INK
6084
p.title.text_font_size = "48pt"
85+
p.xaxis.axis_label_text_color = INK
86+
p.yaxis.axis_label_text_color = INK
6187
p.xaxis.axis_label_text_font_size = "36pt"
6288
p.yaxis.axis_label_text_font_size = "36pt"
89+
p.xaxis.major_label_text_color = INK_SOFT
90+
p.yaxis.major_label_text_color = INK_SOFT
6391
p.xaxis.major_label_text_font_size = "28pt"
6492
p.yaxis.major_label_text_font_size = "28pt"
93+
p.xaxis.axis_line_color = INK_SOFT
94+
p.yaxis.axis_line_color = INK_SOFT
95+
p.xaxis.major_tick_line_color = INK_SOFT
96+
p.yaxis.major_tick_line_color = INK_SOFT
6597

66-
# Grid styling
67-
p.grid.grid_line_alpha = 0.3
68-
p.grid.grid_line_dash = "dashed"
98+
p.xgrid.grid_line_color = None # y-only grid preferred for line charts
99+
p.ygrid.grid_line_color = INK
100+
p.ygrid.grid_line_alpha = 0.10
69101

70-
# Legend styling
102+
# Legend — top-left for better visual balance
71103
p.legend.label_text_font_size = "28pt"
72-
p.legend.location = "bottom_right"
73-
p.legend.background_fill_alpha = 0.7
74-
75-
# Save as PNG and HTML
76-
export_png(p, filename="plot.png")
104+
p.legend.location = "top_left"
105+
p.legend.background_fill_color = ELEVATED_BG
106+
p.legend.border_line_color = INK_SOFT
107+
p.legend.label_text_color = INK_SOFT
77108

78-
output_file("plot.html")
109+
# Save
110+
export_png(p, filename=f"plot-{THEME}.png")
111+
output_file(f"plot-{THEME}.html")
79112
save(p)
Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,66 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
span-basic: Basic Span Plot (Highlighted Region)
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.13.13
4+
Quality: 91/100 | Updated: 2026-04-30
55
"""
66

7+
import os
8+
79
import matplotlib.pyplot as plt
810
import numpy as np
911

1012

11-
# Data - Stock prices with highlighted recession period
12-
np.random.seed(42)
13-
dates = np.arange(2006, 2016, 0.1) # 10 years of data
13+
# Theme tokens
14+
THEME = os.getenv("ANYPLOT_THEME", "light")
15+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
16+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
17+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
18+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
19+
INK_MUTED = "#6B6A63" if THEME == "light" else "#A8A79F"
1420

15-
# Simulate stock price with trend and volatility
16-
price = 100 + np.cumsum(np.random.randn(len(dates)) * 2)
21+
BRAND = "#009E73" # Okabe-Ito position 1 — first series
22+
C2 = "#D55E00" # Okabe-Ito position 2
23+
C3 = "#0072B2" # Okabe-Ito position 3
24+
25+
# Data — stock prices with a simulated recession dip
26+
np.random.seed(42)
27+
dates = np.arange(2004, 2016, 0.1)
1728

18-
# Add a dip during recession period (2008-2009)
29+
price = 100 + np.cumsum(np.random.randn(len(dates)) * 1.5)
1930
recession_mask = (dates >= 2008) & (dates < 2010)
20-
price[recession_mask] -= np.linspace(0, 30, recession_mask.sum())
21-
price[dates >= 2010] -= 30
22-
price = price + np.abs(price.min()) + 50 # Keep positive
31+
price[recession_mask] -= np.linspace(0, 35, recession_mask.sum())
32+
price[dates >= 2010] -= 35
33+
price = price - price.min() + 70
34+
35+
# Plot
36+
fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)
37+
ax.set_facecolor(PAGE_BG)
38+
39+
ax.plot(dates, price, linewidth=3, color=BRAND, label="Stock Price Index")
40+
41+
# Vertical span — recession period (2008–2009)
42+
ax.axvspan(2008, 2010, alpha=0.22, color=C2, label="Recession Period")
2343

24-
# Create plot (4800x2700 px)
25-
fig, ax = plt.subplots(figsize=(16, 9))
44+
# Horizontal span — risk zone (low values)
45+
ax.axhspan(70, 95, alpha=0.18, color=C3, label="Risk Zone")
2646

27-
# Plot line data
28-
ax.plot(dates, price, linewidth=3, color="#306998", label="Stock Price")
47+
# Style
48+
ax.set_xlabel("Year", fontsize=20, color=INK)
49+
ax.set_ylabel("Price Index", fontsize=20, color=INK)
50+
ax.set_title("span-basic · matplotlib · anyplot.ai", fontsize=24, fontweight="medium", color=INK)
51+
ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT, labelcolor=INK_SOFT)
2952

30-
# Vertical span highlighting recession period (2008-2009)
31-
ax.axvspan(2008, 2009, alpha=0.25, color="#FFD43B", label="Recession Period")
53+
ax.spines["top"].set_visible(False)
54+
ax.spines["right"].set_visible(False)
55+
for spine in ("left", "bottom"):
56+
ax.spines[spine].set_color(INK_SOFT)
3257

33-
# Horizontal span highlighting danger zone (low values)
34-
ax.axhspan(60, 80, alpha=0.2, color="#D62728", label="Risk Zone")
58+
ax.yaxis.grid(True, alpha=0.12, linewidth=0.8, color=INK)
3559

36-
# Labels and styling
37-
ax.set_xlabel("Year", fontsize=20)
38-
ax.set_ylabel("Price ($)", fontsize=20)
39-
ax.set_title("span-basic · matplotlib · pyplots.ai", fontsize=24)
40-
ax.tick_params(axis="both", labelsize=16)
41-
ax.grid(True, alpha=0.3, linestyle="--")
42-
ax.legend(fontsize=16, loc="upper left")
60+
leg = ax.legend(fontsize=16, loc="upper left")
61+
leg.get_frame().set_facecolor(ELEVATED_BG)
62+
leg.get_frame().set_edgecolor(INK_SOFT)
63+
plt.setp(leg.get_texts(), color=INK_SOFT)
4364

4465
plt.tight_layout()
45-
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
66+
plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG)
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)