Skip to content

Commit f456628

Browse files
update(pie-basic): letsplot — comprehensive quality review (#4223)
## Summary Updated **letsplot** implementation for **pie-basic**. **Changes:** Comprehensive review improving code quality, data choice, visual design, spec compliance, and library feature usage. ## Test Plan - [x] Preview images uploaded to GCS staging - [x] Implementation file passes ruff format/check - [x] Metadata YAML updated with current versions - [ ] Automated review triggered --- Generated with [Claude Code](https://claude.com/claude-code) `/update` command --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent bc5273c commit f456628

2 files changed

Lines changed: 181 additions & 137 deletions

File tree

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,62 @@
11
""" pyplots.ai
22
pie-basic: Basic Pie Chart
3-
Library: letsplot 4.8.1 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: letsplot 4.8.2 | Python 3.14.0
4+
Quality: 82/100 | Created: 2025-12-23
55
"""
66

7-
import pandas as pd
87
from lets_plot import * # noqa: F403
9-
from lets_plot.export import ggsave as export_ggsave
8+
from lets_plot import ggsave
109

1110

1211
LetsPlot.setup_html() # noqa: F405
1312

14-
# Data - Market share by company
15-
categories = ["Company A", "Company B", "Company C", "Company D", "Company E"]
16-
values = [35, 25, 20, 12, 8]
13+
# Data - Global smartphone market share (2024)
14+
data = {
15+
"company": ["Apple", "Samsung", "Xiaomi", "OPPO", "Others"],
16+
"share": [23.1, 19.4, 13.7, 8.8, 35.0],
17+
"explode": [0.0, 0.0, 0.0, 0.12, 0.0],
18+
}
1719

18-
df = pd.DataFrame({"category": categories, "value": values})
20+
# Colors - Python Blue first, then colorblind-safe palette
21+
colors = ["#306998", "#FFD43B", "#4CAF50", "#AB47BC", "#90A4AE"]
1922

20-
# Calculate percentages for labels
21-
total = sum(values)
22-
df["pct"] = df["value"] / total * 100
23-
24-
# Preserve category order
25-
df["category"] = pd.Categorical(df["category"], categories=categories, ordered=True)
26-
27-
# Define colors - Python Blue first, then colorblind-safe palette
28-
colors = ["#306998", "#FFD43B", "#4CAF50", "#FF7043", "#AB47BC"]
29-
30-
# Plot
23+
# Plot — square canvas fills space evenly for circular pie charts
3124
plot = (
32-
ggplot(df) # noqa: F405
25+
ggplot(data) # noqa: F405
3326
+ geom_pie( # noqa: F405
34-
aes(slice="value", fill="category"), # noqa: F405
27+
aes(slice="share", fill="company", explode="explode"), # noqa: F405
3528
stat="identity",
36-
size=20, # Large size for visibility at 4800x2700
37-
hole=0, # Full pie (not donut)
29+
size=75,
30+
hole=0,
31+
stroke=2,
32+
stroke_side="both",
33+
color="white",
34+
spacer_width=1.5,
35+
spacer_color="white",
3836
labels=layer_labels() # noqa: F405
39-
.line("@pct")
40-
.format("pct", "{.1f}%")
41-
.size(14),
37+
.line("@{share}")
38+
.format("share", "{.1f}%")
39+
.size(18),
4240
)
4341
+ scale_fill_manual(values=colors) # noqa: F405
4442
+ labs( # noqa: F405
45-
title="pie-basic · letsplot · pyplots.ai", fill="Category"
43+
title="Global Smartphone Market Share · pie-basic · letsplot · pyplots.ai",
44+
subtitle="OPPO's 8.8% slice is the smallest — 'Others' dominate at 35%",
45+
fill="Brand",
4646
)
47-
+ ggsize(1600, 900) # noqa: F405
47+
+ ggsize(1200, 1200) # noqa: F405
4848
+ theme_void() # noqa: F405
4949
+ theme( # noqa: F405
50-
plot_title=element_text(size=24, hjust=0.5), # noqa: F405
51-
legend_title=element_text(size=18), # noqa: F405
52-
legend_text=element_text(size=16), # noqa: F405
50+
plot_title=element_text(size=26, hjust=0.5, face="bold"), # noqa: F405
51+
plot_subtitle=element_text(size=16, hjust=0.5, color="#555555"), # noqa: F405
52+
legend_title=element_text(size=20), # noqa: F405
53+
legend_text=element_text(size=18), # noqa: F405
54+
plot_margin=[30, 20, 30, 20],
55+
legend_position="bottom",
56+
legend_direction="horizontal",
5357
)
5458
)
5559

5660
# Save
57-
export_ggsave(plot, filename="plot.png", path=".", scale=3)
58-
export_ggsave(plot, filename="plot.html", path=".")
61+
ggsave(plot, filename="plot.png", path=".", scale=3)
62+
ggsave(plot, filename="plot.html", path=".")

0 commit comments

Comments
 (0)