Skip to content

Commit 667227f

Browse files
update(violin-basic): altair — comprehensive quality review
Comprehensive quality review improving code quality, data choice, visual design, spec compliance, and library feature usage.
1 parent e9894a3 commit 667227f

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

plots/violin-basic/implementations/altair.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" pyplots.ai
22
violin-basic: Basic Violin Plot
3-
Library: altair 6.0.0 | Python 3.13.11
4-
Quality: 92/100 | Created: 2025-12-23
3+
Library: altair 6.0.0 | Python 3.14.3
4+
Quality: /100 | Updated: 2026-02-21
55
"""
66

77
import altair as alt
@@ -16,39 +16,34 @@
1616

1717
for cat in categories:
1818
if cat == "Engineering":
19-
# Higher salaries with moderate spread
2019
values = np.random.normal(92000, 16000, 150)
2120
elif cat == "Marketing":
22-
# Mid-range salaries
2321
values = np.random.normal(70000, 13000, 150)
2422
elif cat == "Sales":
2523
# Bimodal: base salary + high performers with commissions
2624
values = np.concatenate([np.random.normal(50000, 8000, 75), np.random.normal(92000, 11000, 75)])
2725
else: # Support
28-
# Lower salary, tighter distribution
2926
values = np.random.normal(55000, 10000, 150)
3027

3128
for v in values:
3229
data.append({"Department": cat, "Salary": v})
3330

3431
df = pd.DataFrame(data)
3532

36-
# Calculate statistics for quartile markers
33+
# Merge quartile statistics for layering
3734
stats = (
3835
df.groupby("Department")["Salary"]
3936
.agg(q1=lambda x: x.quantile(0.25), median=lambda x: x.quantile(0.5), q3=lambda x: x.quantile(0.75))
4037
.reset_index()
4138
)
39+
df = df.merge(stats, on="Department")
4240

43-
# Merge stats for layering
44-
df_with_stats = df.merge(stats, on="Department")
45-
46-
# Colors - Python palette
47-
colors = ["#306998", "#FFD43B", "#4B8BBE", "#FFE873"]
41+
# Colors - cohesive colorblind-safe palette starting with Python Blue
42+
colors = ["#306998", "#E5832D", "#4B8BBE", "#8B6C42"]
4843
color_scale = alt.Scale(domain=categories, range=colors)
4944

5045
# Base chart
51-
base = alt.Chart(df_with_stats)
46+
base = alt.Chart(df)
5247

5348
# Violin shape using kernel density transform
5449
violin = (
@@ -69,14 +64,17 @@
6964
axis=alt.Axis(labels=False, values=[0], grid=False, ticks=False),
7065
),
7166
color=alt.Color("Department:N", scale=color_scale, legend=None),
67+
tooltip=[alt.Tooltip("Department:N"), alt.Tooltip("Salary:Q", format="$,.0f")],
7268
)
7369
)
7470

75-
# IQR rule (black vertical line)
76-
quartile_rule = base.mark_rule(color="black", strokeWidth=5).encode(y="q1:Q", y2="q3:Q")
71+
# IQR rule (dark line from Q1 to Q3)
72+
quartile_rule = base.mark_rule(color="#1a1a1a", strokeWidth=5).encode(y="q1:Q", y2="q3:Q")
7773

78-
# Median point (white dot with black border)
79-
median_point = base.mark_point(color="white", size=250, filled=True, strokeWidth=3, stroke="black").encode(y="median:Q")
74+
# Median point (white dot with dark border)
75+
median_point = base.mark_point(color="white", size=250, filled=True, strokeWidth=3, stroke="#1a1a1a").encode(
76+
y="median:Q", tooltip=[alt.Tooltip("Department:N"), alt.Tooltip("median:Q", title="Median Salary", format="$,.0f")]
77+
)
8078

8179
# Combine layers and facet by department
8280
chart = (
@@ -92,7 +90,7 @@
9290
.properties(title=alt.Title("violin-basic · altair · pyplots.ai", fontSize=28, anchor="middle"))
9391
.configure_facet(spacing=20)
9492
.configure_view(stroke=None, continuousWidth=350, continuousHeight=750)
95-
.configure_axis(labelFontSize=18, titleFontSize=22, gridOpacity=0.3, gridDash=[3, 3])
93+
.configure_axis(labelFontSize=18, titleFontSize=22, gridOpacity=0.2, gridDash=[3, 3])
9694
)
9795

9896
# Save outputs

plots/violin-basic/metadata/altair.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: altair
22
specification_id: violin-basic
33
created: '2025-12-23T00:38:09Z'
4-
updated: '2025-12-23T00:42:01Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-21T22:25:00+00:00'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20447779967
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 6.0.0
8+
python_version: '3.14.3'
9+
library_version: '6.0.0'
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/violin-basic/altair/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/violin-basic/altair/plot_thumb.png
1212
preview_html: https://storage.googleapis.com/pyplots-images/plots/violin-basic/altair/plot.html
13-
quality_score: 92
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:

0 commit comments

Comments
 (0)