Skip to content

Commit cec3b05

Browse files
update(density-basic): plotnine — comprehensive quality review
Comprehensive quality review: geom_area+geom_line layering, fixed rug color, cleaner grid.
1 parent 2dd92c8 commit cec3b05

2 files changed

Lines changed: 27 additions & 20 deletions

File tree

plots/density-basic/implementations/plotnine.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
""" pyplots.ai
22
density-basic: Basic Density 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-23
55
"""
66

77
import numpy as np
88
import pandas as pd
99
from plotnine import (
1010
aes,
11+
after_stat,
1112
coord_cartesian,
13+
element_blank,
1214
element_line,
1315
element_text,
14-
geom_density,
16+
geom_area,
17+
geom_line,
1518
geom_rug,
1619
ggplot,
1720
labs,
1821
scale_x_continuous,
22+
scale_y_continuous,
1923
theme,
2024
theme_minimal,
2125
)
@@ -29,27 +33,30 @@
2933
np.random.normal(88, 5, 50), # High achievers
3034
]
3135
)
32-
test_scores = np.clip(test_scores, 0, 100) # Scores between 0-100
36+
test_scores = np.clip(test_scores, 0, 100)
3337

3438
df = pd.DataFrame({"score": test_scores})
3539

36-
# Plot with bandwidth adjustment for smoother curve
40+
# Plot - layered density using stat_density for filled area + outline
3741
plot = (
3842
ggplot(df, aes(x="score"))
39-
+ geom_density(fill="#306998", color="#306998", alpha=0.6, size=1.5, bw="scott")
40-
+ geom_rug(color="#FFD43B", alpha=0.7, size=1)
43+
+ geom_area(aes(y=after_stat("density")), stat="density", fill="#306998", alpha=0.5, color="none")
44+
+ geom_line(aes(y=after_stat("density")), stat="density", color="#1a3d5c", size=1.8)
45+
+ geom_rug(color="#306998", alpha=0.4, size=0.8)
4146
+ labs(x="Test Score (points)", y="Probability Density", title="density-basic · plotnine · pyplots.ai")
42-
+ scale_x_continuous(limits=(30, 100), breaks=range(30, 101, 10))
43-
+ coord_cartesian(xlim=(30, 100))
47+
+ scale_x_continuous(breaks=range(40, 101, 10))
48+
+ scale_y_continuous(expand=(0, 0, 0.05, 0))
49+
+ coord_cartesian(xlim=(40, 102))
4450
+ theme_minimal()
4551
+ theme(
4652
figure_size=(16, 9),
4753
text=element_text(size=14),
4854
axis_title=element_text(size=20),
4955
axis_text=element_text(size=16),
5056
plot_title=element_text(size=24),
51-
panel_grid_major=element_line(color="#cccccc", alpha=0.3),
52-
panel_grid_minor=element_line(color="#eeeeee", alpha=0.2),
57+
panel_grid_major_x=element_blank(),
58+
panel_grid_minor=element_blank(),
59+
panel_grid_major_y=element_line(color="#cccccc", alpha=0.2, size=0.5),
5360
)
5461
)
5562

plots/density-basic/metadata/plotnine.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
library: plotnine
22
specification_id: density-basic
33
created: '2025-12-23T10:00:30Z'
4-
updated: '2025-12-23T10:04:55Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-23T22:38:00+00:00'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20457535942
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 0.15.2
8+
python_version: 3.14.3
9+
library_version: 0.15.3
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/density-basic/plotnine/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/density-basic/plotnine/plot_thumb.png
1212
preview_html: null
13-
quality_score: 91
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:
17-
- layer-composition
17+
- layer-composition
1818
patterns:
19-
- data-generation
19+
- data-generation
2020
dataprep:
21-
- kde
21+
- kde
2222
styling:
23-
- alpha-blending
23+
- alpha-blending
2424
review:
2525
strengths:
2626
- Clean plotnine grammar of graphics implementation using geom_density with appropriate

0 commit comments

Comments
 (0)