Skip to content

Commit b523eb5

Browse files
feat(plotnine): implement line-basic (#5538)
## Implementation: `line-basic` - python/plotnine Implements the **python/plotnine** version of `line-basic`. **File:** `plots/line-basic/implementations/python/plotnine.py` **Parent Issue:** #653 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/anyplot/actions/runs/25117213621)* --------- 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 c29e63b commit b523eb5

2 files changed

Lines changed: 208 additions & 146 deletions

File tree

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
1-
""" pyplots.ai
1+
""" anyplot.ai
22
line-basic: Basic Line 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: 89/100 | Updated: 2026-04-29
55
"""
66

7+
import os
8+
import sys
9+
10+
11+
# Prevent this file from shadowing the plotnine library when run from its own directory
12+
sys.path = [p for p in sys.path if not p or os.path.abspath(p) != os.path.abspath(os.path.dirname(__file__))]
13+
714
import numpy as np
815
import pandas as pd
9-
from plotnine import aes, element_line, element_text, geom_line, geom_point, ggplot, labs, theme, theme_minimal
16+
from plotnine import (
17+
aes,
18+
element_line,
19+
element_rect,
20+
element_text,
21+
geom_line,
22+
geom_point,
23+
ggplot,
24+
labs,
25+
scale_x_continuous,
26+
theme,
27+
theme_minimal,
28+
)
29+
1030

31+
# Theme tokens
32+
THEME = os.getenv("ANYPLOT_THEME", "light")
33+
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
34+
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
35+
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"
36+
BRAND = "#009E73"
1137

1238
# Data - Monthly average temperature readings for a typical year
1339
np.random.seed(42)
@@ -17,22 +43,27 @@
1743

1844
df = pd.DataFrame({"Month": months, "Temperature": temperature})
1945

46+
month_labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
47+
2048
# Plot
2149
plot = (
2250
ggplot(df, aes(x="Month", y="Temperature"))
23-
+ geom_line(size=2.5, color="#306998")
24-
+ geom_point(size=6, color="#306998")
25-
+ labs(x="Month", y="Temperature (°C)", title="line-basic · plotnine · pyplots.ai")
51+
+ geom_line(size=2.5, color=BRAND)
52+
+ geom_point(size=6, color=BRAND)
53+
+ scale_x_continuous(breaks=list(range(1, 13)), labels=month_labels)
54+
+ labs(x="Month", y="Temperature (°C)", title="line-basic · plotnine · anyplot.ai")
2655
+ theme_minimal()
2756
+ theme(
2857
figure_size=(16, 9),
29-
text=element_text(size=14),
30-
axis_title=element_text(size=20),
31-
axis_text=element_text(size=16),
32-
plot_title=element_text(size=24),
33-
panel_grid_major=element_line(color="#cccccc", size=0.5, alpha=0.3),
34-
panel_grid_minor=element_line(color="#eeeeee", size=0.3, alpha=0.2),
58+
plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),
59+
panel_background=element_rect(fill=PAGE_BG),
60+
text=element_text(size=14, color=INK),
61+
axis_title=element_text(size=20, color=INK),
62+
axis_text=element_text(size=16, color=INK_SOFT),
63+
plot_title=element_text(size=24, color=INK),
64+
panel_grid_major=element_line(color=INK_SOFT, size=0.3, alpha=0.15),
65+
panel_grid_minor=element_line(color=INK_SOFT, size=0.2, alpha=0.05),
3566
)
3667
)
3768

38-
plot.save("plot.png", dpi=300, verbose=False)
69+
plot.save(f"plot-{THEME}.png", dpi=300, verbose=False)

0 commit comments

Comments
 (0)