Skip to content

Commit 5335c66

Browse files
feat(plotnine): implement strip-basic (#5674)
## Implementation: `strip-basic` - python/plotnine Implements the **python/plotnine** version of `strip-basic`. **File:** `plots/strip-basic/implementations/python/plotnine.py` **Parent Issue:** #975 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25342823556)* --------- 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 30fd977 commit 5335c66

2 files changed

Lines changed: 189 additions & 148 deletions

File tree

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
strip-basic: Basic Strip Plot
3-
Library: plotnine 0.15.2 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: plotnine 0.15.3 | Python 3.13.13
4+
Quality: 85/100 | Updated: 2026-05-04
55
"""
66

7+
import os
8+
79
import numpy as np
810
import pandas as pd
911
from plotnine import (
1012
aes,
13+
element_line,
14+
element_rect,
1115
element_text,
1216
geom_point,
1317
ggplot,
@@ -19,44 +23,52 @@
1923
)
2024

2125

26+
# Theme tokens
27+
THEME = os.getenv("ANYPLOT_THEME", "light")
28+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
29+
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
30+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
31+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
32+
33+
OKABE_ITO = ["#009E73", "#D55E00", "#0072B2", "#CC79A7"]
34+
2235
# Data - Patient response times (seconds) across different drug treatments
2336
np.random.seed(42)
2437

25-
treatments = ["Placebo", "Drug A", "Drug B", "Drug C"]
26-
data = []
27-
28-
# Generate varied distributions for each treatment group
2938
distributions = {
3039
"Placebo": {"mean": 45, "std": 12, "n": 40},
3140
"Drug A": {"mean": 32, "std": 8, "n": 45},
3241
"Drug B": {"mean": 28, "std": 10, "n": 42},
3342
"Drug C": {"mean": 25, "std": 6, "n": 38},
3443
}
3544

45+
data = []
3646
for treatment, params in distributions.items():
3747
times = np.random.normal(params["mean"], params["std"], params["n"])
38-
# Clip to realistic response times (minimum 5 seconds)
3948
times = np.clip(times, 5, 80)
4049
data.extend([(treatment, time) for time in times])
4150

4251
df = pd.DataFrame(data, columns=["treatment", "response_time"])
4352

44-
# Create strip plot with jittered points
53+
# Plot
4554
plot = (
4655
ggplot(df, aes(x="treatment", y="response_time", color="treatment"))
4756
+ geom_point(position=position_jitter(width=0.25, height=0, random_state=42), size=4, alpha=0.65)
48-
+ scale_color_manual(values=["#306998", "#FFD43B", "#4B8BBE", "#FFE873"])
49-
+ labs(x="Treatment Group", y="Response Time (seconds)", title="strip-basic · plotnine · pyplots.ai")
57+
+ scale_color_manual(values=OKABE_ITO)
58+
+ labs(x="Treatment Group", y="Response Time (seconds)", title="strip-basic · plotnine · anyplot.ai")
5059
+ theme_minimal()
5160
+ theme(
5261
figure_size=(16, 9),
53-
text=element_text(size=14),
54-
axis_title=element_text(size=20),
55-
axis_text=element_text(size=16),
56-
plot_title=element_text(size=24),
62+
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
63+
panel_background=element_rect(fill=PAGE_BG),
64+
panel_grid_major=element_line(color=INK, size=0.3, alpha=0.20),
65+
panel_grid_minor=element_line(color=INK, size=0.15, alpha=0.08),
66+
axis_title=element_text(color=INK, size=20),
67+
axis_text=element_text(color=INK_SOFT, size=16),
68+
plot_title=element_text(color=INK, size=24),
5769
legend_position="none",
5870
)
5971
)
6072

6173
# Save
62-
plot.save("plot.png", dpi=300, verbose=False)
74+
plot.save(f"plot-{THEME}.png", dpi=300, verbose=False)

0 commit comments

Comments
 (0)