Skip to content

Commit ebb20b3

Browse files
update(bubble-packed): letsplot — comprehensive quality review
Comprehensive review improving code quality, data choice, visual design, spec compliance, and library feature usage.
1 parent 7e47de1 commit ebb20b3

2 files changed

Lines changed: 27 additions & 39 deletions

File tree

plots/bubble-packed/implementations/letsplot.py

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
""" pyplots.ai
1+
"""pyplots.ai
22
bubble-packed: Basic Packed Bubble Chart
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.3
4+
Quality: /100 | Updated: 2026-02-23
55
"""
66

77
import numpy as np
@@ -16,6 +16,7 @@
1616
ggplot,
1717
ggsize,
1818
labs,
19+
layer_tooltips,
1920
scale_color_manual,
2021
scale_size,
2122
theme,
@@ -28,7 +29,7 @@
2829

2930
LetsPlot.setup_html()
3031

31-
# Data - department budget allocation
32+
# Data - department budget allocation ($M)
3233
np.random.seed(42)
3334
categories = [
3435
"Engineering",
@@ -66,9 +67,9 @@
6667
"Tech",
6768
]
6869

69-
# Circle packing using force simulation (inline)
70+
# Circle packing using force simulation
7071
n = len(values)
71-
radii = np.sqrt(values / np.pi) * 3.5 # Scale by area for accurate visual perception
72+
radii = np.sqrt(values / np.pi) * 3.5
7273

7374
# Initialize positions
7475
np.random.seed(42)
@@ -77,11 +78,9 @@
7778

7879
# Force-directed packing simulation
7980
for _ in range(600):
80-
# Pull toward center
8181
x *= 0.99
8282
y *= 0.99
8383

84-
# Push overlapping circles apart
8584
for i in range(n):
8685
for j in range(i + 1, n):
8786
dx = x[j] - x[i]
@@ -98,33 +97,25 @@
9897
x[j] += move_x
9998
y[j] += move_y
10099

101-
df = pd.DataFrame({"label": categories, "value": values, "group": groups, "x": x, "y": y})
100+
df = pd.DataFrame(
101+
{"label": categories, "value": values, "group": groups, "x": x, "y": y, "budget": [f"${v}M" for v in values]}
102+
)
102103

103-
# Abbreviate long labels to fit inside bubbles
104-
label_map = {
105-
"Customer Support": "Support",
106-
"Engineering": "Engineering",
107-
"Marketing": "Marketing",
108-
"Sales": "Sales",
109-
"Operations": "Ops",
110-
"Finance": "Finance",
111-
"R&D": "R&D",
112-
"HR": "HR",
113-
"Legal": "Legal",
114-
"IT": "IT",
115-
"Product": "Product",
116-
"Design": "Design",
117-
"Analytics": "Analytics",
118-
"QA": "QA",
119-
"Security": "Security",
120-
}
121-
df["short_label"] = df["label"].map(label_map)
104+
# Show labels only on bubbles large enough to fit text
105+
df["display_label"] = df.apply(lambda row: row["label"] if row["value"] >= 35 else "", axis=1)
106+
# Abbreviate long labels
107+
abbrev = {"Customer Support": "Support", "Operations": "Ops"}
108+
df["display_label"] = df["display_label"].replace(abbrev)
122109

123110
# Plot
124111
plot = (
125112
ggplot(df, aes(x="x", y="y"))
126-
+ geom_point(aes(size="value", color="group"), alpha=0.85)
127-
+ geom_text(aes(label="short_label"), size=7, color="white", fontface="bold")
113+
+ geom_point(
114+
aes(size="value", color="group"),
115+
alpha=0.85,
116+
tooltips=layer_tooltips().title("@label").line("Budget|@budget").line("Division|@group"),
117+
)
118+
+ geom_text(aes(label="display_label"), size=7, color="white", fontface="bold")
128119
+ scale_size(range=[20, 85], guide="none")
129120
+ scale_color_manual(values=["#FFD43B", "#4ECDC4", "#306998"])
130121
+ labs(title="Department Budget Allocation · bubble-packed · letsplot · pyplots.ai", color="Division")
@@ -141,8 +132,5 @@
141132
+ ggsize(1600, 900)
142133
)
143134

144-
# Save PNG (scale 3x to get 4800x2700 px)
135+
# Save
145136
export_ggsave(plot, "plot.png", path=".", scale=3)
146-
147-
# Save HTML for interactive version
148-
export_ggsave(plot, "plot.html", path=".")

plots/bubble-packed/metadata/letsplot.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: letsplot
22
specification_id: bubble-packed
33
created: '2025-12-23T09:15:56Z'
4-
updated: '2025-12-23T09:18:05Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: 2026-02-23T15:35:00+00:00
5+
generated_by: claude-opus-4-6
66
workflow_run: 20456562981
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 4.8.2
8+
python_version: "3.14.3"
9+
library_version: "4.8.2"
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/bubble-packed/letsplot/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bubble-packed/letsplot/plot_thumb.png
1212
preview_html: https://storage.googleapis.com/pyplots-images/plots/bubble-packed/letsplot/plot.html
13-
quality_score: 91
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:

0 commit comments

Comments
 (0)