Skip to content

Commit 3835929

Browse files
update(density-basic): letsplot — comprehensive quality review
Comprehensive quality review: marathon data, ggsave fix, tooltips, trim parameter.
1 parent 2dd92c8 commit 3835929

2 files changed

Lines changed: 45 additions & 24 deletions

File tree

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,62 @@
11
""" pyplots.ai
22
density-basic: Basic Density Plot
3-
Library: letsplot 4.8.2 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: letsplot 4.8.2 | Python 3.14
4+
Quality: /100 | Updated: 2026-02-23
55
"""
66

77
import numpy as np
8+
import pandas as pd
89
from lets_plot import * # noqa: F403
9-
from lets_plot.export import ggsave as export_ggsave
1010

1111

1212
LetsPlot.setup_html() # noqa: F405
1313

14-
# Data - Generate realistic test scores with slight right skew
14+
# Data - Simulated marathon finish times with realistic right skew
1515
np.random.seed(42)
16-
scores = np.concatenate(
16+
finish_minutes = np.concatenate(
1717
[
18-
np.random.normal(72, 12, 300), # Main group of students
19-
np.random.normal(90, 5, 100), # High achievers
18+
np.random.normal(240, 25, 350), # Main pack (~4 hour runners)
19+
np.random.normal(200, 15, 100), # Competitive runners (~3:20)
20+
np.random.normal(300, 20, 50), # Casual runners (~5 hours)
2021
]
2122
)
23+
finish_minutes = np.clip(finish_minutes, 140, 400)
2224

23-
# Create plot
25+
df = pd.DataFrame({"time": finish_minutes})
26+
27+
# Plot
2428
plot = (
25-
ggplot({"scores": scores}, aes(x="scores")) # noqa: F405
26-
+ geom_density(fill="#306998", color="#306998", alpha=0.6, size=1.5) # noqa: F405
27-
+ labs(x="Test Score", y="Density", title="density-basic · letsplot · pyplots.ai") # noqa: F405
29+
ggplot(df, aes(x="time")) # noqa: F405
30+
+ geom_density( # noqa: F405
31+
fill="#306998",
32+
color="#1e4263",
33+
alpha=0.55,
34+
size=1.8,
35+
kernel="gaussian",
36+
adjust=0.85,
37+
trim=True,
38+
tooltips=layer_tooltips() # noqa: F405
39+
.line("@|@time")
40+
.line("density|@..density.."),
41+
)
42+
+ labs( # noqa: F405
43+
x="Finish Time (minutes)", y="Density", title="density-basic · letsplot · pyplots.ai"
44+
)
45+
+ scale_x_continuous(breaks=list(range(150, 401, 50))) # noqa: F405
46+
+ scale_y_continuous(expand=[0.02, 0, 0.05, 0]) # noqa: F405
2847
+ theme_minimal() # noqa: F405
2948
+ theme( # noqa: F405
3049
axis_title=element_text(size=20), # noqa: F405
3150
axis_text=element_text(size=16), # noqa: F405
3251
plot_title=element_text(size=24), # noqa: F405
33-
panel_grid_major=element_line(color="#cccccc", size=0.5), # noqa: F405
52+
panel_grid_major_x=element_blank(), # noqa: F405
53+
panel_grid_major_y=element_line(color="#e0e0e0", size=0.4), # noqa: F405
3454
panel_grid_minor=element_blank(), # noqa: F405
55+
axis_ticks=element_blank(), # noqa: F405
3556
)
3657
+ ggsize(1600, 900) # noqa: F405
3758
)
3859

39-
# Save PNG (scale 3x for 4800x2700) and HTML
40-
export_ggsave(plot, "plot.png", path=".", scale=3)
41-
export_ggsave(plot, "plot.html", path=".")
60+
# Save PNG (scale 3x for 4800 x 2700 px) and HTML
61+
ggsave(plot, "plot.png", path=".", scale=3) # noqa: F405
62+
ggsave(plot, "plot.html", path=".") # noqa: F405

plots/density-basic/metadata/letsplot.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
library: letsplot
22
specification_id: density-basic
33
created: '2025-12-23T10:03:24Z'
4-
updated: '2025-12-23T10:11:02Z'
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: 20457538654
77
issue: 0
8-
python_version: 3.13.11
8+
python_version: 3.14.3
99
library_version: 4.8.2
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/density-basic/letsplot/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/density-basic/letsplot/plot_thumb.png
1212
preview_html: https://storage.googleapis.com/pyplots-images/plots/density-basic/letsplot/plot.html
13-
quality_score: 91
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:
17-
- layer-composition
18-
- html-export
17+
- layer-composition
18+
- html-export
1919
patterns:
20-
- data-generation
20+
- data-generation
2121
dataprep:
22-
- kde
22+
- kde
2323
styling:
24-
- alpha-blending
24+
- alpha-blending
2525
review:
2626
strengths:
2727
- Clean ggplot2-style grammar implementation with proper layering

0 commit comments

Comments
 (0)