diff --git a/plots/funnel-basic/implementations/python/seaborn.py b/plots/funnel-basic/implementations/python/seaborn.py index 22234c6e1f..db673bc9a5 100644 --- a/plots/funnel-basic/implementations/python/seaborn.py +++ b/plots/funnel-basic/implementations/python/seaborn.py @@ -1,111 +1,163 @@ -""" pyplots.ai +""" anyplot.ai funnel-basic: Basic Funnel Chart -Library: seaborn 0.13.2 | Python 3.13.11 -Quality: 91/100 | Created: 2025-12-23 +Library: seaborn 0.13.2 | Python 3.14.4 +Quality: 90/100 | Updated: 2026-04-26 """ +import os + import matplotlib.pyplot as plt -import numpy as np import seaborn as sns from matplotlib.patches import Polygon -# Set seed for reproducibility -np.random.seed(42) +# Theme tokens +THEME = os.getenv("ANYPLOT_THEME", "light") +PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17" +INK = "#1A1A17" if THEME == "light" else "#F0EFE8" +INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0" +INK_MUTED = "#6B6A63" if THEME == "light" else "#A8A79F" + +# Okabe-Ito palette — first series always #009E73 +OKABE_ITO = ["#009E73", "#D55E00", "#0072B2", "#CC79A7", "#E69F00"] -# Data - Sales funnel example from specification +# Sales funnel data stages = ["Awareness", "Interest", "Consideration", "Intent", "Purchase"] values = [1000, 600, 400, 200, 100] max_value = values[0] - -# Calculate percentages percentages = [v / max_value * 100 for v in values] +conversions = [values[i + 1] / values[i] * 100 for i in range(len(values) - 1)] +# Stage transition with the largest drop-off (lowest retention) +worst_idx = min(range(len(conversions)), key=conversions.__getitem__) + +sns.set_theme( + style="white", + rc={ + "figure.facecolor": PAGE_BG, + "axes.facecolor": PAGE_BG, + "text.color": INK, + "axes.labelcolor": INK, + "ytick.color": INK, + "xtick.color": INK_SOFT, + }, +) + +fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG) +ax.set_facecolor(PAGE_BG) + +# Seaborn draws the rectangular core of each stage; trapezoidal panels added +# below tie the cores into a continuous funnel silhouette in stage colors. +sns.barplot( + x=values, + y=stages, + hue=stages, + order=stages, + palette=OKABE_ITO[: len(stages)], + ax=ax, + legend=False, + width=0.50, + edgecolor="none", +) + +# Center each bar on x=0 so the silhouette narrows symmetrically +bars = list(ax.patches)[: len(stages)] +for patch in bars: + patch.set_x(-patch.get_width() / 2) + +# Trapezoidal panels between stages — each panel inherits the upper stage color +# so visually each stage = rectangle + tapering trapezoid below it. +for i in range(len(bars) - 1): + p_top, p_bot = bars[i], bars[i + 1] + top_y = p_top.get_y() + p_top.get_height() + bot_y = p_bot.get_y() + ax.add_patch( + Polygon( + [ + (p_top.get_x(), top_y), + (p_top.get_x() + p_top.get_width(), top_y), + (p_bot.get_x() + p_bot.get_width(), bot_y), + (p_bot.get_x(), bot_y), + ], + facecolor=OKABE_ITO[i], + edgecolor="none", + zorder=1, + ) + ) + +# Closing tail below the last stage so the funnel ends with a proper taper +last_bar = bars[-1] +last_top_y = last_bar.get_y() + last_bar.get_height() +tail_height = 0.50 +tail_bot_w = last_bar.get_width() * 0.5 +ax.add_patch( + Polygon( + [ + (last_bar.get_x(), last_top_y), + (last_bar.get_x() + last_bar.get_width(), last_top_y), + (tail_bot_w / 2, last_top_y + tail_height), + (-tail_bot_w / 2, last_top_y + tail_height), + ], + facecolor=OKABE_ITO[-1], + edgecolor="none", + zorder=1, + ) +) + +# Emphasise the bar after the worst drop-off with a thicker outline accent +worst_bar = bars[worst_idx + 1] +worst_bar.set_edgecolor(INK) +worst_bar.set_linewidth(2.5) +worst_bar.set_zorder(3) + +# Value + percentage labels are placed OUTSIDE bars (right) so narrow stages +# never overflow onto the page background. +right_offset = max_value * 0.04 +for i, patch in enumerate(bars): + cy = patch.get_y() + patch.get_height() / 2 + x_right = patch.get_x() + patch.get_width() + ax.text( + x_right + right_offset, + cy, + f"{values[i]:,} · {percentages[i]:.0f}%", + ha="left", + va="center", + fontsize=18, + fontweight="medium", + color=INK, + ) -# Seaborn styling -sns.set_theme(style="white") - -# Create figure -fig, ax = plt.subplots(figsize=(16, 9)) - -# Color palette using Python Blue to Gold progression -colors = sns.color_palette(["#306998", "#4078A8", "#6AA8D1", "#FFD43B", "#E8C547"]) - -# Funnel parameters -n_stages = len(stages) -funnel_height = 0.8 # Total height of funnel -stage_gap = 0.02 # Gap between stages -stage_height = (funnel_height - (n_stages - 1) * stage_gap) / n_stages -center_x = 0.5 - -# Draw trapezoidal funnel segments -for i in range(n_stages): - # Calculate widths - proportional to value relative to max - top_width = values[i] / max_value * 0.8 - # Bottom width is the next stage's width, or smaller for last stage - if i < n_stages - 1: - bottom_width = values[i + 1] / max_value * 0.8 - else: - bottom_width = values[i] / max_value * 0.8 * 0.6 # Narrower bottom for last stage - - # Calculate y positions (top to bottom) - y_top = 1 - 0.1 - i * (stage_height + stage_gap) - y_bottom = y_top - stage_height - - # Create trapezoid vertices (clockwise from top-left) - vertices = [ - (center_x - top_width / 2, y_top), # Top-left - (center_x + top_width / 2, y_top), # Top-right - (center_x + bottom_width / 2, y_bottom), # Bottom-right - (center_x - bottom_width / 2, y_bottom), # Bottom-left - ] - - # Draw trapezoid using matplotlib Polygon - trapezoid = Polygon(vertices, facecolor=colors[i], edgecolor="white", linewidth=3, closed=True) - ax.add_patch(trapezoid) - - # Calculate center of trapezoid for label placement - center_y = (y_top + y_bottom) / 2 - - # Add stage name on the left +# Conversion-rate annotations on the LEFT, with the largest drop-off +# rendered bolder and in full-strength ink for visual emphasis. +left_anchor = -max_value / 2 - max_value * 0.06 +for i in range(len(conversions)): + p_top, p_bot = bars[i], bars[i + 1] + y_mid = (p_top.get_y() + p_top.get_height() + p_bot.get_y()) / 2 + is_worst = i == worst_idx ax.text( - center_x - top_width / 2 - 0.05, - center_y, - stages[i], + left_anchor, + y_mid, + f"↓ {conversions[i]:.0f}%", ha="right", va="center", - fontsize=20, - fontweight="bold", - color="#333333", + fontsize=16 if is_worst else 13, + fontweight="bold" if is_worst else "normal", + style="italic", + color=INK if is_worst else INK_MUTED, ) - # Add value and percentage label in center - label_text = f"{values[i]:,} ({percentages[i]:.0f}%)" - # Choose text color based on background brightness - text_color = "white" if i < 3 else "#333333" - ax.text(center_x, center_y, label_text, ha="center", va="center", fontsize=18, fontweight="bold", color=text_color) - - # Add conversion rate between stages - if i < n_stages - 1: - conversion_rate = values[i + 1] / values[i] * 100 - ax.text( - center_x + top_width / 2 + 0.05, - y_bottom, - f"↓ {conversion_rate:.0f}%", - ha="left", - va="center", - fontsize=14, - color="#666666", - style="italic", - ) +# Awareness on top — matplotlib's default places the first category at the bottom +ax.invert_yaxis() +ax.set_ylim(len(stages) - 1 + tail_height + 0.25, -0.45) + +sns.despine(ax=ax, left=True, bottom=True) +ax.set_xticks([]) +ax.set_xlabel("") +ax.set_ylabel("") +ax.tick_params(axis="y", labelsize=20, length=0, pad=10) -# Set axis limits and remove decorations -ax.set_xlim(0, 1) -ax.set_ylim(0, 1) -ax.set_aspect("equal") -ax.axis("off") +ax.set_xlim(-max_value * 0.95, max_value * 0.85) -# Title -ax.set_title("funnel-basic · seaborn · pyplots.ai", fontsize=24, fontweight="bold", pad=20) +ax.set_title("funnel-basic · seaborn · anyplot.ai", fontsize=24, fontweight="medium", color=INK, pad=20) plt.tight_layout() -plt.savefig("plot.png", dpi=300, bbox_inches="tight", facecolor="white") +plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG) diff --git a/plots/funnel-basic/metadata/python/seaborn.yaml b/plots/funnel-basic/metadata/python/seaborn.yaml index c2ed5205b0..ca04d01ca7 100644 --- a/plots/funnel-basic/metadata/python/seaborn.yaml +++ b/plots/funnel-basic/metadata/python/seaborn.yaml @@ -1,146 +1,189 @@ library: seaborn +language: python specification_id: funnel-basic created: '2025-12-23T13:04:46Z' -updated: '2025-12-23T13:38:26Z' -generated_by: claude-opus-4-5-20251101 -workflow_run: 20461374089 -issue: 0 -python_version: 3.13.11 +updated: '2026-04-26T05:57:01Z' +generated_by: claude-opus +workflow_run: 24949059229 +issue: 789 +python_version: 3.14.4 library_version: 0.13.2 -preview_url: https://storage.googleapis.com/anyplot-images/plots/funnel-basic/seaborn/plot.png -preview_html: null -quality_score: 91 -impl_tags: - dependencies: [] - techniques: - - patches - - annotations - patterns: - - data-generation - dataprep: [] - styling: - - minimal-chrome +preview_url_light: https://storage.googleapis.com/anyplot-images/plots/funnel-basic/python/seaborn/plot-light.png +preview_url_dark: https://storage.googleapis.com/anyplot-images/plots/funnel-basic/python/seaborn/plot-dark.png +preview_html_light: null +preview_html_dark: null +quality_score: 90 review: strengths: - - Excellent visual design with well-proportioned trapezoidal segments - - Clear blue-to-gold color progression that aids visual hierarchy - - 'Perfect text contrast: white text on blue, dark text on gold backgrounds' - - Uses exact data from specification (sales funnel example) - - Clean code structure following KISS principles - - Proper title format matching specification requirements + - Creative use of sns.barplot as scaffold for a custom funnel shape with trapezoidal + Polygon patches + - 'Correct Okabe-Ito palette (first series #009E73), both themes properly themed + with no dark-on-dark failures' + - 'Visual storytelling: worst drop-off highlighted with bold conversion annotation + and edge outline on the next stage bar' + - Perfect spec compliance — ordered stages, distinct per-stage colors, value+percentage + labels, proportional widths + - Clean, deterministic flat code with correct seaborn 0.14+ hue/palette/legend=False + API weaknesses: - - Conversion rate annotations (coded in lines 88-99) are not visible in the rendered - output - may be positioned outside canvas bounds - - Could use seaborn color palette more distinctively (e.g., using a named sequential - palette) - image_description: 'The plot displays a funnel chart for a sales pipeline with 5 - stages arranged vertically from top to bottom: Awareness (1,000 / 100%), Interest - (600 / 60%), Consideration (400 / 40%), Intent (200 / 20%), and Purchase (100 - / 10%). Each stage is rendered as a trapezoidal segment with widths proportional - to their values. The color palette transitions from deep blue (#306998) at the - top through lighter blues to gold/yellow (#FFD43B, #E8C547) at the bottom. Stage - names appear on the left side in bold dark gray text, while values with percentages - are centered within each segment in white (for blue segments) or dark text (for - gold segments). The title "funnel-basic · seaborn · pyplots.ai" appears at the - top. The layout is clean with a white background and good spacing between segments.' + - Non-emphasized conversion-rate annotations at 13pt fall below the 16pt guideline + for secondary labels — raise all to 16pt or remove distinction + - 16:9 landscape canvas leaves noticeable horizontal whitespace; a square canvas + (3600×3600) or taller aspect would suit the funnel shape better + image_description: |- + Light render (plot-light.png): + Background: Warm off-white #FAF8F1 — correct, not pure white. + Chrome: Title "funnel-basic · seaborn · anyplot.ai" in dark ink at 24pt — clearly readable. Stage names (Awareness, Interest, Consideration, Intent, Purchase) in dark INK on left at 20pt — all readable. Conversion-rate annotations (↓60%, ↓67%, ↓50%, ↓50%) in INK_MUTED on the right — visible. Worst drop-off annotation (↓50% between Consideration and Intent) rendered bold and in full INK for emphasis. + Data: Five trapezoidal segments in Okabe-Ito order — #009E73 (Awareness), #D55E00 (Interest), #0072B2 (Consideration), #CC79A7 (Intent), #E69F00 (Purchase). Value+percentage labels ("1,000 · 100%", "600 · 60%", etc.) positioned to the right of each bar in INK color. The Intent bar carries a bold dark edge outline highlighting the worst conversion drop-off. Closing tail gives the funnel a clean pointed tip. + Legibility verdict: PASS — all text readable; minor concern: non-emphasized conversion labels at 13pt are slightly below the 16pt guideline but still legible at full resolution. + + Dark render (plot-dark.png): + Background: Warm near-black #1A1A17 — correct, not pure black. + Chrome: Title in near-white #F0EFE8 — clearly readable against dark background. Stage names in light INK token — readable. Conversion-rate annotations in muted #A8A79F — visible. No dark-on-dark failures detected anywhere. + Data: Identical Okabe-Ito colors to light render (#009E73, #D55E00, #0072B2, #CC79A7, #E69F00) — data identity preserved across themes. Value labels in near-white INK, clean contrast on dark background. Intent bar edge outline switches to INK (#F0EFE8) — visible as a light edge on the dark surface. + Legibility verdict: PASS — all text elements readable in dark theme; value labels on dark background are highly legible. criteria_checklist: visual_quality: - score: 36 - max: 40 + score: 28 + max: 30 items: - id: VQ-01 name: Text Legibility - score: 10 - max: 10 + score: 7 + max: 8 passed: true - comment: Title at 24pt, stage names at 20pt, values at 18pt - all perfectly - readable + comment: Title 24pt, stage names 20pt, value labels 18pt, worst conversion + 16pt — all explicitly set. Non-emphasized conversion labels at 13pt fall + below 16pt guideline for secondary text. - id: VQ-02 name: No Overlap - score: 8 - max: 8 + score: 6 + max: 6 passed: true - comment: No overlapping text, all labels clearly separated + comment: Stage names, value labels, and conversion annotations cleanly separated + across all stages including the narrowest ones - id: VQ-03 name: Element Visibility - score: 8 - max: 8 + score: 6 + max: 6 passed: true - comment: Trapezoid segments are well-sized and clearly visible + comment: All five funnel segments visible including narrow Intent and Purchase + stages; closing tail provides a clean bottom tip - id: VQ-04 name: Color Accessibility - score: 4 - max: 5 + score: 2 + max: 2 passed: true - comment: Blue-to-gold gradient is colorblind-friendly, though the gold shades - are similar + comment: Okabe-Ito palette is CVD-safe; five distinct hues, no red-green sole + signal - id: VQ-05 - name: Layout Balance + name: Layout & Canvas + score: 3 + max: 4 + passed: true + comment: Funnel well-centered and proportioned; 16:9 canvas leaves noticeable + horizontal whitespace since the funnel is taller than wide + - id: VQ-06 + name: Axis Labels & Title + score: 2 + max: 2 + passed: true + comment: Title matches required format; stage names serve as labels; no traditional + axis labels needed for funnel chart + - id: VQ-07 + name: Palette Compliance + score: 2 + max: 2 + passed: true + comment: 'First stage #009E73, Okabe-Ito order through position 5, FAF8F1/1A1A17 + backgrounds correct in both themes, chrome flips correctly' + design_excellence: + score: 15 + max: 20 + items: + - id: DE-01 + name: Aesthetic Sophistication + score: 6 + max: 8 + passed: true + comment: 'Strong design clearly above defaults: custom funnel geometry, Okabe-Ito + per-stage colors, intentional typography hierarchy, and storytelling emphasis + on worst drop-off' + - id: DE-02 + name: Visual Refinement + score: 5 + max: 6 + passed: true + comment: 'All spines removed, no grid, x-axis ticks hidden, y-axis tick marks + hidden, clean closing tail — near-perfect refinement. Minor: horizontal + whitespace in 16:9 canvas for tall funnel.' + - id: DE-03 + name: Data Storytelling score: 4 - max: 5 + max: 6 passed: true - comment: Good use of canvas, funnel is well-centered, though conversion rate - annotations on the right are missing from the rendered output + comment: Funnel shape narrates conversion; worst drop-off highlighted with + bold conversion annotation (↓50%, bold+italic+INK) and edge outline on Intent + bar; visual hierarchy guides reader to key insight spec_compliance: - score: 23 - max: 25 + score: 15 + max: 15 items: - id: SC-01 name: Plot Type - score: 8 - max: 8 - passed: true - comment: Correct funnel chart with trapezoidal segments narrowing top to bottom - - id: SC-02 - name: Data Mapping score: 5 max: 5 passed: true - comment: Stages correctly ordered from largest to smallest - - id: SC-03 + comment: Correct funnel chart with trapezoidal segments narrowing proportionally + top to bottom + - id: SC-02 name: Required Features score: 4 - max: 5 + max: 4 passed: true - comment: Has value labels, percentages, distinct colors; conversion rates - coded but not visible in output - - id: SC-04 - name: Data Range + comment: Ordered stages largest to smallest, distinct per-stage colors, value+percentage + labels, proportional widths — all present + - id: SC-03 + name: Data Mapping score: 3 max: 3 passed: true - comment: All 5 stages displayed with correct proportions - - id: SC-06 - name: Title Format - score: 2 - max: 2 + comment: Sales funnel stages as y-axis, values as bar width, properly decreasing + top to bottom + - id: SC-04 + name: Title & Legend + score: 3 + max: 3 passed: true - comment: 'Correct format: "funnel-basic · seaborn · pyplots.ai"' + comment: Title 'funnel-basic · seaborn · anyplot.ai' correct; no legend needed + as stage names serve as labels data_quality: - score: 20 - max: 20 + score: 15 + max: 15 items: - id: DQ-01 name: Feature Coverage - score: 8 - max: 8 + score: 6 + max: 6 passed: true - comment: Shows progressive decrease across all stages, demonstrates funnel - drop-off pattern well + comment: 'All funnel aspects shown: widths, stage names, absolute values, + percentage of total, stage-to-stage conversion rates with varying drop-offs' - id: DQ-02 name: Realistic Context - score: 7 - max: 7 + score: 5 + max: 5 passed: true - comment: Uses the exact sales funnel example from the specification + comment: Classic marketing funnel (Awareness→Purchase) is a real-world, neutral, + widely-recognized business scenario - id: DQ-03 name: Appropriate Scale - score: 5 - max: 5 + score: 4 + max: 4 passed: true - comment: Values (1000→100) are realistic for a conversion funnel + comment: 1000 to 100 with 50-67% conversion rates reflects typical sales pipeline; + realistic and appropriate code_quality: - score: 9 + score: 10 max: 10 items: - id: CQ-01 @@ -148,42 +191,65 @@ review: score: 3 max: 3 passed: true - comment: 'Linear flow: imports → data → plot → save, no functions/classes' + comment: 'Flat script: imports → tokens → data → theme → plot → labels → save; + no functions or classes' - id: CQ-02 name: Reproducibility - score: 3 - max: 3 + score: 2 + max: 2 passed: true - comment: Uses np.random.seed(42) + comment: Fully deterministic hardcoded data; no random generation needed - id: CQ-03 name: Clean Imports - score: 1 + score: 2 max: 2 passed: true - comment: numpy imported but seed not strictly necessary for deterministic - data + comment: 'All imports used: os, matplotlib.pyplot, seaborn, matplotlib.patches.Polygon' - id: CQ-04 - name: No Deprecated API - score: 1 - max: 1 + name: Code Elegance + score: 2 + max: 2 passed: true - comment: Uses current matplotlib/seaborn APIs + comment: Appropriate complexity for custom chart type; clean loops; comments + explain non-obvious geometry decisions; no fake UI - id: CQ-05 - name: Output Correct + name: Output & API score: 1 max: 1 passed: true - comment: Saves as plot.png with correct parameters - library_features: - score: 3 - max: 5 + comment: Saves as plot-{THEME}.png with dpi=300, bbox_inches=tight, facecolor=PAGE_BG + library_mastery: + score: 7 + max: 10 items: - - id: LF-01 - name: Uses seaborn styling + - id: LM-01 + name: Idiomatic Usage + score: 4 + max: 5 + passed: true + comment: 'Uses seaborn 0.14+ idiomatic API: hue=stages+palette+legend=False + for per-bar coloring, sns.set_theme() for comprehensive chrome configuration, + sns.despine() for spine management. Core funnel geometry unavoidably uses + matplotlib patches (no seaborn funnel primitive).' + - id: LM-02 + name: Distinctive Features score: 3 max: 5 passed: true - comment: Uses sns.set_theme() and sns.color_palette(), but core drawing uses - matplotlib Polygon; this is acceptable since seaborn doesn't have a native - funnel chart + comment: hue-based per-bar coloring with legend=False is a seaborn-distinctive + pattern not easily replicated in plain matplotlib; sns.set_theme() and sns.despine() + are seaborn-specific. Core polygon geometry is matplotlib. verdict: APPROVED +impl_tags: + dependencies: [] + techniques: + - patches + - annotations + - manual-ticks + patterns: + - explicit-figure + - iteration-over-groups + dataprep: [] + styling: + - minimal-chrome + - edge-highlighting