Skip to content

Commit a29efa4

Browse files
update(box-basic): plotnine — comprehensive quality review and improvement
1 parent 150c632 commit a29efa4

2 files changed

Lines changed: 48 additions & 23 deletions

File tree

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,75 @@
11
""" pyplots.ai
22
box-basic: Basic Box 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.14
4+
Quality: /100 | Updated: 2026-02-14
55
"""
66

77
import numpy as np
88
import pandas as pd
9-
from plotnine import aes, element_text, geom_boxplot, ggplot, labs, theme, theme_minimal
9+
from plotnine import (
10+
aes,
11+
coord_cartesian,
12+
element_blank,
13+
element_line,
14+
element_text,
15+
geom_boxplot,
16+
ggplot,
17+
labs,
18+
scale_fill_brewer,
19+
theme,
20+
theme_minimal,
21+
)
1022

1123

1224
# Data
1325
np.random.seed(42)
14-
categories = ["Engineering", "Marketing", "Sales", "Support"]
15-
data = {"category": [], "value": []}
26+
categories = ["Engineering", "Marketing", "Sales", "Support", "Research"]
27+
records = []
1628

17-
# Generate salary data for each department with varied distributions
1829
for cat in categories:
19-
n = np.random.randint(50, 150)
30+
n = np.random.randint(60, 120)
2031
if cat == "Engineering":
2132
values = np.random.normal(95000, 15000, n)
2233
elif cat == "Marketing":
2334
values = np.random.normal(75000, 12000, n)
2435
elif cat == "Sales":
25-
values = np.random.normal(70000, 20000, n)
26-
else: # Support
27-
values = np.random.normal(55000, 10000, n)
28-
data["category"].extend([cat] * n)
29-
data["value"].extend(values)
36+
base = np.random.normal(68000, 18000, n)
37+
outliers = np.random.uniform(120000, 145000, 5)
38+
values = np.concatenate([base, outliers])
39+
elif cat == "Support":
40+
values = np.random.normal(55000, 8000, n)
41+
else: # Research
42+
values = np.random.normal(85000, 20000, n)
43+
records.extend({"department": cat, "salary": v} for v in values)
3044

31-
df = pd.DataFrame(data)
45+
df = pd.DataFrame(records)
46+
dept_order = ["Support", "Marketing", "Sales", "Research", "Engineering"]
47+
df["department"] = pd.Categorical(df["department"], categories=dept_order, ordered=True)
3248

3349
# Plot
3450
plot = (
35-
ggplot(df, aes(x="category", y="value", fill="category"))
36-
+ geom_boxplot(outlier_size=3, outlier_alpha=0.6, size=0.8)
37-
+ labs(x="Department", y="Salary ($)", title="box-basic · plotnine · pyplots.ai")
51+
ggplot(df, aes(x="department", y="salary", fill="department"))
52+
+ geom_boxplot(outlier_size=2.5, outlier_alpha=0.5, outlier_colour="#555555", size=0.6, alpha=0.85)
53+
+ scale_fill_brewer(type="qual", palette="Set2")
54+
+ coord_cartesian(ylim=(25000, 155000))
55+
+ labs(x="Department", y="Salary ($)", title="box-basic \u00b7 plotnine \u00b7 pyplots.ai")
3856
+ theme_minimal()
3957
+ theme(
4058
figure_size=(16, 9),
4159
text=element_text(size=14),
60+
plot_title=element_text(size=24, weight="bold"),
4261
axis_title=element_text(size=20),
4362
axis_text=element_text(size=16),
44-
plot_title=element_text(size=24),
4563
legend_position="none",
64+
panel_grid_major_x=element_blank(),
65+
panel_grid_minor=element_blank(),
66+
panel_grid_major_y=element_line(color="#DDDDDD", size=0.5, alpha=0.4),
67+
axis_line_x=element_line(color="#333333", size=0.5),
68+
axis_line_y=element_line(color="#333333", size=0.5),
69+
axis_ticks_major_x=element_blank(),
70+
axis_ticks_major_y=element_blank(),
4671
)
4772
)
4873

4974
# Save
50-
plot.save("plot.png", dpi=300, verbose=False)
75+
plot.save("plot.png", dpi=300)

plots/box-basic/metadata/plotnine.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: plotnine
22
specification_id: box-basic
33
created: '2025-12-23T00:36:35Z'
4-
updated: '2025-12-23T00:40:39Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: 2026-02-14T22:09:08+00:00
5+
generated_by: claude-opus-4-6
66
workflow_run: 20447781993
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 0.15.2
8+
python_version: "3.14"
9+
library_version: "0.15.3"
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/box-basic/plotnine/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/box-basic/plotnine/plot_thumb.png
1212
preview_html: null
13-
quality_score: 91
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques: []

0 commit comments

Comments
 (0)