Skip to content

Commit c80f004

Browse files
feat(matplotlib): implement cat-box-strip (#6523)
## Implementation: `cat-box-strip` - python/matplotlib Implements the **python/matplotlib** version of `cat-box-strip`. **File:** `plots/cat-box-strip/implementations/python/matplotlib.py` **Parent Issue:** #2695 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25780220870)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 8385f2b commit c80f004

2 files changed

Lines changed: 206 additions & 142 deletions

File tree

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
cat-box-strip: Box Plot with Strip Overlay
3-
Library: matplotlib 3.10.8 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-30
3+
Library: matplotlib 3.10.9 | Python 3.13.13
4+
Quality: 91/100 | Updated: 2026-05-13
55
"""
66

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

1012

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+
20+
BRAND = "#009E73" # Okabe-Ito position 1
21+
1122
# Data - Generate groups with different distributions to showcase features
1223
np.random.seed(42)
1324

@@ -31,8 +42,9 @@
3142
box_data = [data[cat] for cat in categories]
3243
positions = np.arange(len(categories)) + 1
3344

34-
# Create plot
35-
fig, ax = plt.subplots(figsize=(16, 9))
45+
# Plot
46+
fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)
47+
ax.set_facecolor(PAGE_BG)
3648

3749
# Box plot
3850
ax.boxplot(
@@ -41,29 +53,44 @@
4153
tick_labels=categories,
4254
widths=0.5,
4355
patch_artist=True,
44-
boxprops={"facecolor": "#306998", "alpha": 0.4, "linewidth": 2},
45-
medianprops={"color": "#FFD43B", "linewidth": 3},
46-
whiskerprops={"color": "#306998", "linewidth": 2},
47-
capprops={"color": "#306998", "linewidth": 2},
48-
flierprops={"marker": "o", "markerfacecolor": "#306998", "markersize": 10, "alpha": 0.7},
56+
boxprops={"facecolor": BRAND, "alpha": 0.4, "linewidth": 2, "edgecolor": INK_SOFT},
57+
medianprops={"color": "#E69F00", "linewidth": 3},
58+
whiskerprops={"color": INK_SOFT, "linewidth": 2},
59+
capprops={"color": INK_SOFT, "linewidth": 2},
60+
flierprops={
61+
"marker": "o",
62+
"markerfacecolor": BRAND,
63+
"markersize": 10,
64+
"alpha": 0.7,
65+
"markeredgecolor": INK_SOFT,
66+
"markeredgewidth": 1,
67+
},
4968
)
5069

5170
# Strip plot overlay - add jittered points
5271
for pos, cat in zip(positions, categories, strict=True):
5372
y = data[cat]
5473
# Jitter x positions
5574
x = np.random.normal(pos, 0.08, len(y))
56-
ax.scatter(x, y, s=100, alpha=0.6, color="#306998", edgecolor="white", linewidth=1, zorder=3)
75+
ax.scatter(x, y, s=100, alpha=0.6, color=BRAND, edgecolor=PAGE_BG, linewidth=1, zorder=3)
76+
77+
# Style
78+
ax.set_xlabel("Treatment Group", fontsize=20, color=INK)
79+
ax.set_ylabel("Response Value (score)", fontsize=20, color=INK)
80+
ax.set_title("cat-box-strip · matplotlib · anyplot.ai", fontsize=24, fontweight="medium", color=INK)
81+
ax.tick_params(axis="both", labelsize=16, colors=INK_SOFT, labelcolor=INK_SOFT)
82+
83+
# Spines
84+
ax.spines["top"].set_visible(False)
85+
ax.spines["right"].set_visible(False)
86+
for s in ("left", "bottom"):
87+
ax.spines[s].set_color(INK_SOFT)
5788

58-
# Labels and styling
59-
ax.set_xlabel("Treatment Group", fontsize=20)
60-
ax.set_ylabel("Response Value", fontsize=20)
61-
ax.set_title("cat-box-strip · matplotlib · pyplots.ai", fontsize=24)
62-
ax.tick_params(axis="both", labelsize=16)
63-
ax.grid(True, axis="y", alpha=0.3, linestyle="--")
89+
# Grid
90+
ax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)
6491

6592
# Adjust y-axis to show all data including outliers
6693
ax.set_ylim(0, 100)
6794

6895
plt.tight_layout()
69-
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
96+
plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG)

0 commit comments

Comments
 (0)